Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(ide): free side panel layout with several panes, stacking, swapping and drag-out (#901)

Ruben Lütke8bc56c171d7d
diff --git a/dodaios/ui/web/frontend/src/components/agentic/sidePanel/IdeSidePanel.test.tsx b/dodaios/ui/web/frontend/src/components/agentic/sidePanel/IdeSidePanel.test.tsx
index 3333c56123..9ad485ce92 100644
--- a/dodaios/ui/web/frontend/src/components/agentic/sidePanel/IdeSidePanel.test.tsx
+++ b/dodaios/ui/web/frontend/src/components/agentic/sidePanel/IdeSidePanel.test.tsx
@@ -41,7 +41,7 @@ beforeEach(() => {
useWorkspacePanesStore.setState({ panes: [], activeId: null, loaded: true, load: async () => {} });
useIdeProjectsStore.setState({ activeWorkspaceId: null });
useEventStore.setState({ activeSection: "agentic-ide" });
- useIdeSidePanelStore.setState({ open: false, tabs: ["agents"], active: "agents", terminals: [], maximized: false, inUse: false, split: null, splitRatio: 0.5, focusedColumn: 0 });
+ useIdeSidePanelStore.setState({ open: false, tabs: ["agents"], active: "agents", terminals: [], maximized: false, inUse: false, layout: null, focusedPane: null });
useIdeChatStore.setState({ workspace: { id: "w1", name: "App", path: "/code/app" } });
});
@@ -372,21 +372,41 @@ describe("IdeSidePanel", () => {
act(() => useIdeSidePanelStore.getState().setOpen(false));
expect(useIdeSidePanelStore.getState().inUse).toBe(false);
});
+ const rect = (left: number, top: number, width: number, height: number) =>
+ ({ left, top, width, height, right: left + width, bottom: top + height, x: left, y: top, toJSON: () => ({}) });
+ /** Content area 800x600 under a 44px strip, so drops can be aimed in jsdom. */
+ const aim = () => {
+ vi.stubGlobal("PointerEvent", PointerEventStub);
+ screen.getByTestId("ide-side-panel-content").getBoundingClientRect = () => rect(0, 50, 800, 600);
+ screen.getByRole("tablist").getBoundingClientRect = () => rect(0, 0, 700, 44);
+ };
+ const drag = (from: HTMLElement, to: { x: number; y: number }) => {
+ const box = { clientX: 20, clientY: 20 };
+ fireEvent.pointerDown(from, { button: 0, ...box });
+ fireEvent.pointerMove(window, { clientX: to.x + 3, clientY: to.y + 3 });
+ fireEvent.pointerMove(window, { clientX: to.x, clientY: to.y });
+ fireEvent.pointerUp(window, { clientX: to.x, clientY: to.y });
+ fireEvent.click(from);
+ };
+ const paneTabs = () => [...document.querySelectorAll<HTMLElement>("[data-testid^='ide-side-panel-pane-header-']")]
+ .map((node) => node.dataset.testid!.replace("ide-side-panel-pane-header-", ""));
+ const twoPanes = () => {
+ act(() => useIdeSidePanelStore.setState({ open: true, tabs: ["agents", "files", "changes"], active: "agents" }));
+ act(() => useIdeSidePanelStore.getState().dropTab("files", null, "right"));
+ };
+
it("shows two tabs side by side from the split button and joins them back", () => {
act(() => useIdeSidePanelStore.setState({ open: true, tabs: ["agents", "files"], active: "agents" }));
render(<Harness />);
fireEvent.click(screen.getByTestId("ide-side-panel-split"));
- expect(useIdeSidePanelStore.getState()).toMatchObject({ active: "agents", split: "files", focusedColumn: 1 });
- expect(screen.getByTestId("ide-side-panel-content").dataset.split).toBe("true");
- expect(screen.getByTestId("ide-side-panel-column-agents")).toBeTruthy();
- expect(screen.getByTestId("ide-side-panel-column-files")).toBeTruthy();
- expect(screen.getByTestId("ide-side-panel-split-resizer")).toBeTruthy();
- // Both visible tabs read as selected in the strip.
+ expect(screen.getByTestId("ide-side-panel-content").dataset.panes).toBe("2");
+ expect(paneTabs()).toEqual(["agents", "files"]);
+ expect(useIdeSidePanelStore.getState().active).toBe("files");
expect(screen.getByTestId("ide-side-panel-tab-agents").getAttribute("aria-selected")).toBe("true");
expect(screen.getByTestId("ide-side-panel-tab-files").getAttribute("aria-selected")).toBe("true");
fireEvent.click(screen.getByTestId("ide-side-panel-split"));
- expect(useIdeSidePanelStore.getState()).toMatchObject({ active: "files", split: null });
- expect(screen.queryByTestId("ide-side-panel-column-agents")).toBeNull();
+ expect(useIdeSidePanelStore.getState()).toMatchObject({ layout: null, active: "files" });
+ expect(paneTabs()).toEqual([]);
});
it("disables the split button while only one tab is open", () => {
@@ -395,57 +415,80 @@ describe("IdeSidePanel", () => {
expect((screen.getByTestId("ide-side-panel-split") as HTMLButtonElement).disabled).toBe(true);
});
- it("splits when a tab is dragged onto the left half of the panel", () => {
- vi.stubGlobal("PointerEvent", PointerEventStub);
+ it("stacks a tab dragged onto the bottom edge under the one in front", () => {
act(() => useIdeSidePanelStore.setState({ open: true, tabs: ["agents", "files"], active: "agents" }));
render(<Harness />);
- const content = screen.getByTestId("ide-side-panel-content");
- content.getBoundingClientRect = () => ({ left: 0, top: 50, right: 800, bottom: 650, width: 800, height: 600, x: 0, y: 50, toJSON: () => ({}) });
- fireEvent.pointerDown(screen.getByTestId("ide-side-panel-tab-files"), { button: 0, clientX: 300, clientY: 20 });
- // A small wobble is still a click, not a drag.
+ aim();
+ const tab = screen.getByTestId("ide-side-panel-tab-files");
+ fireEvent.pointerDown(tab, { button: 0, clientX: 300, clientY: 20 });
fireEvent.pointerMove(window, { clientX: 302, clientY: 21 });
expect(screen.queryByTestId("ide-side-panel-drop-zones")).toBeNull();
- fireEvent.pointerMove(window, { clientX: 150, clientY: 300 });
+ fireEvent.pointerMove(window, { clientX: 400, clientY: 630 });
expect(screen.getByTestId("ide-side-panel-drop-zones").hasAttribute("data-hides-native-browser")).toBe(true);
- expect(screen.getByTestId("ide-side-panel-drop-left").dataset.over).toBe("true");
- fireEvent.pointerUp(window, { clientX: 150, clientY: 300 });
- fireEvent.click(screen.getByTestId("ide-side-panel-tab-files"));
- expect(useIdeSidePanelStore.getState()).toMatchObject({ active: "files", split: "agents", focusedColumn: 0 });
- expect(screen.queryByTestId("ide-side-panel-drop-zones")).toBeNull();
+ expect(screen.getByTestId("ide-side-panel-drop-bottom")).toBeTruthy();
+ fireEvent.pointerUp(window, { clientX: 400, clientY: 630 });
+ fireEvent.click(tab);
+ const { layout } = useIdeSidePanelStore.getState();
+ expect(layout).toMatchObject({ kind: "split", direction: "column" });
+ expect(paneTabs()).toEqual(["agents", "files"]);
+ expect(useIdeSidePanelStore.getState().active).toBe("files");
});
- it("cancels a tab drag on Escape or a release outside the panel", () => {
- vi.stubGlobal("PointerEvent", PointerEventStub);
+ it("adds a third pane and swaps two panes by dragging a title bar onto the other", () => {
+ render(<Harness />);
+ twoPanes();
+ aim();
+ // Changes onto the right edge of Folder (the right half of the area).
+ drag(screen.getByTestId("ide-side-panel-tab-changes"), { x: 795, y: 350 });
+ expect(paneTabs()).toEqual(["agents", "files", "changes"]);
+ expect(screen.getByTestId("ide-side-panel-content").dataset.panes).toBe("3");
+ // Agents' title bar onto the middle of Changes (the last third): they trade places.
+ const grip = screen.getByTestId("ide-side-panel-pane-header-agents").querySelector<HTMLElement>("[role='button']")!;
+ drag(grip, { x: 667, y: 350 });
+ expect(paneTabs()).toEqual(["changes", "files", "agents"]);
+ });
+
+ it("takes a pane out of the split by dragging it onto the strip or out of the panel", () => {
+ render(<Harness />);
+ twoPanes();
+ aim();
+ const grip = () => screen.getByTestId("ide-side-panel-pane-header-files").querySelector<HTMLElement>("[role='button']")!;
+ fireEvent.pointerDown(grip(), { button: 0, clientX: 500, clientY: 60 });
+ fireEvent.pointerMove(window, { clientX: 300, clientY: 20 });
+ expect(screen.getByRole("tablist").dataset.detachTarget).toBe("true");
+ fireEvent.pointerUp(window, { clientX: 300, clientY: 20 });
+ expect(useIdeSidePanelStore.getState()).toMatchObject({ layout: null, active: "agents" });
+ expect(useIdeSidePanelStore.getState().tabs).toContain("files");
+ // Split again, then drag the pane away from the panel altogether.
+ act(() => useIdeSidePanelStore.getState().dropTab("files", null, "right"));
+ drag(grip(), { x: 1200, y: 300 });
+ expect(useIdeSidePanelStore.getState().layout).toBeNull();
+ });
+
+ it("cancels a tab drag on Escape and ignores a release outside for a tab not in a split", () => {
act(() => useIdeSidePanelStore.setState({ open: true, tabs: ["agents", "files"], active: "agents" }));
render(<Harness />);
- const content = screen.getByTestId("ide-side-panel-content");
- content.getBoundingClientRect = () => ({ left: 0, top: 50, right: 800, bottom: 650, width: 800, height: 600, x: 0, y: 50, toJSON: () => ({}) });
+ aim();
fireEvent.pointerDown(screen.getByTestId("ide-side-panel-tab-files"), { button: 0, clientX: 300, clientY: 20 });
fireEvent.pointerMove(window, { clientX: 600, clientY: 300 });
fireEvent.keyDown(window, { key: "Escape" });
expect(screen.queryByTestId("ide-side-panel-drop-zones")).toBeNull();
- fireEvent.pointerDown(screen.getByTestId("ide-side-panel-tab-files"), { button: 0, clientX: 300, clientY: 20 });
- fireEvent.pointerMove(window, { clientX: 900, clientY: 300 });
- fireEvent.pointerUp(window, { clientX: 900, clientY: 300 });
- expect(useIdeSidePanelStore.getState().split).toBeNull();
+ drag(screen.getByTestId("ide-side-panel-tab-files"), { x: 1200, y: 300 });
+ expect(useIdeSidePanelStore.getState()).toMatchObject({ layout: null, active: "agents" });
});
- it("puts a clicked tab into the focused column and ends the split when a half closes", () => {
- act(() => useIdeSidePanelStore.setState({ open: true, tabs: ["agents", "files", "changes"], active: "agents" }));
+ it("detaches from the title bar, fills the focused pane on a tab click and closes up when a pane's tab closes", () => {
+ render(<Harness />);
+ twoPanes();
const store = useIdeSidePanelStore.getState;
- act(() => store().splitWith("files", 1));
- expect(store()).toMatchObject({ active: "agents", split: "files", focusedColumn: 1 });
+ expect(store().active).toBe("files");
act(() => store().select("changes"));
- expect(store()).toMatchObject({ active: "agents", split: "changes" });
- act(() => store().select("agents"));
- expect(store().focusedColumn).toBe(0);
- act(() => store().select("files"));
- expect(store()).toMatchObject({ active: "files", split: "changes" });
- // Dropping the left tab on the right swaps the two.
- act(() => store().splitWith("files", 1));
- expect(store()).toMatchObject({ active: "changes", split: "files" });
- act(() => store().closeTab("changes"));
- expect(store()).toMatchObject({ active: "files", split: null, tabs: ["agents", "files"] });
- expect(JSON.parse(localStorage.getItem("jarvis.agenticIde.sidePanelSplit.v1")!)).toMatchObject({ split: null });
+ expect(paneTabs()).toEqual(["agents", "changes"]);
+ fireEvent.click(screen.getByTestId("ide-side-panel-pane-detach-changes"));
+ expect(store()).toMatchObject({ layout: null, active: "agents" });
+ act(() => store().dropTab("files", null, "bottom"));
+ act(() => store().closeTab("files"));
+ expect(store()).toMatchObject({ layout: null, active: "agents", tabs: ["agents", "changes"] });
+ expect(JSON.parse(localStorage.getItem("jarvis.agenticIde.sidePanelLayout.v1")!)).toMatchObject({ layout: null });
});
});
diff --git a/dodaios/ui/web/frontend/src/components/agentic/sidePanel/IdeSidePanel.tsx b/dodaios/ui/web/frontend/src/components/agentic/sidePanel/IdeSidePanel.tsx
index 73fb46ad7e..e533cca828 100644
--- a/dodaios/ui/web/frontend/src/components/agentic/sidePanel/IdeSidePanel.tsx
+++ b/dodaios/ui/web/frontend/src/components/agentic/sidePanel/IdeSidePanel.tsx
@@ -1,10 +1,11 @@
-import { useEffect, useRef, useState, type CSSProperties, type KeyboardEvent as ReactKeyboardEvent, type PointerEvent as ReactPointerEvent, type ReactNode, type RefObject } from "react";
+import { useEffect, useMemo, useRef, useState, type KeyboardEvent as ReactKeyboardEvent, type ReactNode } from "react";
import { Check, Columns2, Maximize2, Minimize2, MoveHorizontal, Plus, SquareTerminal, X } from "lucide-react";
import { useT } from "@/i18n";
import { cn } from "@/lib/utils";
import { useResizablePane } from "@/hooks/useResizablePane";
import { PaneResizer } from "@/components/layout/PaneResizer";
-import { DEFAULT_SPLIT_RATIO, MAX_TERMINAL_TABS, useIdeSidePanelStore, type SidePanelColumn, type SidePanelTabId } from "@/store/ideSidePanel";
+import { MAX_TERMINAL_TABS, useIdeSidePanelStore, type SidePanelTabId } from "@/store/ideSidePanel";
+import { MAX_PANES, columnCount, leaves, placeLayout, type LayoutRect } from "@/store/sidePanelLayout";
import { useIdeChatStore } from "@/store/ideChat";
import { WorkspaceTerminal } from "@/components/workspace/WorkspaceTerminal";
import type { TerminalAppearance } from "../terminalThemes";
@@ -13,6 +14,7 @@ import { usePaneReviewTracking } from "@/store/paneReviews";
import { SIDE_PANEL_TABS, sidePanelTab } from "./sidePanelTabs";
import { SurfaceKbd, SurfaceLauncher, surfaceActionForKey, type SurfaceAction } from "./SurfaceLauncher";
import { SIDE_PANEL_ID } from "./sidePanelIds";
+import { DropPreview, PaneHeader, SplitDividers, paneBox, useDropLabel, useTabDrag, type DragTarget } from "./sidePanelSplit";
const WIDTH_KEY = "jarvis.agenticIde.sidePanelWidth.v1";
const DEFAULT_PX = 340;
@@ -26,10 +28,8 @@ const MIN_PX = 260;
const UNMEASURED_MAX_PX = 4096;
/** The office map needs room to walk around in: its tab opens the panel at least this wide. */
const OFFICE_MIN_PX = 520;
-/** Two tabs side by side need room for both: splitting widens a narrower panel to this once. */
-const SPLIT_MIN_PX = 720;
-/** How far a pressed tab must travel before it counts as dragged rather than clicked. */
-const TAB_DRAG_SLOP_PX = 6;
+/** Panes side by side need room: each column of a split asks for this much, once. */
+const SPLIT_COLUMN_PX = 360;
/** Strip of terminal grid kept beside the panel, so its grip always stays reachable. */
const GRID_RESERVED_PX = 120;
/** Dragging the grip toward the right edge past this width and letting go closes the panel. */
@@ -64,7 +64,7 @@ export function IdeSidePanelFrame({ children, markInUse = false, appearance, onS
const setInUse = useIdeSidePanelStore((state) => state.setInUse);
const setOpen = useIdeSidePanelStore((state) => state.setOpen);
const active = useIdeSidePanelStore((state) => state.active);
- const split = useIdeSidePanelStore((state) => state.split);
+ const layout = useIdeSidePanelStore((state) => state.layout);
const maximized = useIdeSidePanelStore((state) => state.maximized);
const hasTerminals = useIdeSidePanelStore((state) => state.terminals.length > 0);
// Ctrl+click on a path in any terminal opens it in the Explorer tab.
@@ -103,20 +103,20 @@ export function IdeSidePanelFrame({ children, markInUse = false, appearance, onS
// Bringing the office forward widens a narrow panel once; the user can drag
// it back and it stays where they left it until the office is picked again.
- const officeInFront = open && (active === "office" || split === "office");
+ const officeInFront = open && (active === "office" || leaves(layout).some((pane) => pane.tab === "office"));
const paneRef = useRef(pane);
paneRef.current = pane;
useEffect(() => {
if (officeInFront && paneRef.current.size < OFFICE_MIN_PX) paneRef.current.resize(OFFICE_MIN_PX);
}, [officeInFront]);
- // Same for a split: two tabs in a 340px panel would both be cramped.
- const splitShown = open && !!split;
+ // Same for a split: panes side by side in a 340px panel would all be cramped.
+ const columns = open ? columnCount(layout) : 1;
const maxRef = useRef(max);
maxRef.current = max;
useEffect(() => {
- const target = Math.min(SPLIT_MIN_PX, maxRef.current);
- if (splitShown && paneRef.current.size < target) paneRef.current.resize(target);
- }, [splitShown]);
+ const target = Math.min(columns * SPLIT_COLUMN_PX, maxRef.current);
+ if (columns > 1 && paneRef.current.size < target) paneRef.current.resize(target);
+ }, [columns]);
return (
<div ref={frame} className="relative flex h-full min-h-0 w-full">
@@ -208,50 +208,49 @@ export function IdeSidePanel({ appearance, onScreen = true }: { appearance?: Ter
const closeTab = useIdeSidePanelStore((state) => state.closeTab);
const maximized = useIdeSidePanelStore((state) => state.maximized);
const setMaximized = useIdeSidePanelStore((state) => state.setMaximized);
- const storedSplit = useIdeSidePanelStore((state) => state.split);
- const splitRatio = useIdeSidePanelStore((state) => state.splitRatio);
- const focusedColumn = useIdeSidePanelStore((state) => state.focusedColumn);
- const setFocusedColumn = useIdeSidePanelStore((state) => state.setFocusedColumn);
- const setSplitRatio = useIdeSidePanelStore((state) => state.setSplitRatio);
- const splitWith = useIdeSidePanelStore((state) => state.splitWith);
+ const layout = useIdeSidePanelStore((state) => state.layout);
+ const focusedPane = useIdeSidePanelStore((state) => state.focusedPane);
+ const focusPane = useIdeSidePanelStore((state) => state.focusPane);
+ const dropTab = useIdeSidePanelStore((state) => state.dropTab);
+ const detachTab = useIdeSidePanelStore((state) => state.detachTab);
const toggleSplit = useIdeSidePanelStore((state) => state.toggleSplit);
- // A split onto a shell of another workspace shows this workspace's tab alone.
- const split = storedSplit && storedSplit !== active && tabs.includes(storedSplit) ? storedSplit : null;
+ const resizeSplit = useIdeSidePanelStore((state) => state.resizeSplit);
+ const evenOutSplit = useIdeSidePanelStore((state) => state.evenOutSplit);
+ const placed = useMemo(() => placeLayout(layout), [layout]);
+ const split = placed.leaves.length > 1;
+ /** Where each visible tab sits; unsplit, the one in front fills the area. */
+ const rectOf = new Map<SidePanelTabId, LayoutRect>(
+ split ? placed.leaves.map(({ leaf, rect }) => [leaf.tab, rect]) : [[active, { x: 0, y: 0, w: 1, h: 1 }]],
+ );
const content = useRef<HTMLDivElement>(null);
- const tabDrag = useTabDrag(content, split ? splitRatio : DEFAULT_SPLIT_RATIO, splitWith);
- const [resizingSplit, setResizingSplit] = useState(false);
+ const strip = useRef<HTMLDivElement>(null);
+ const tabDrag = useTabDrag({
+ content,
+ strip,
+ panes: split ? placed.leaves.map(({ leaf, rect }) => ({ id: leaf.id, rect })) : [{ id: null, rect: { x: 0, y: 0, w: 1, h: 1 } }],
+ canSplit: (id) => (split ? rectOf.has(id) || placed.leaves.length < MAX_PANES : tabs.length > 1),
+ inSplit: (id) => split && rectOf.has(id),
+ onDrop: (id, target: DragTarget) => {
+ if (target.kind === "detach") detachTab(id);
+ else dropTab(id, target.paneId, target.zone);
+ },
+ });
+ const dropLabel = useDropLabel(tabDrag.target, !!tabDrag.dragging && split && rectOf.has(tabDrag.dragging));
const [menuOpen, setMenuOpen] = useState(false);
const menu = useRef<HTMLDivElement>(null);
- const current = sidePanelTab(active);
const canAddTerminal = !!workspace && terminalCount < MAX_TERMINAL_TABS;
const tabLabel = (id: SidePanelTabId) => {
const terminal = terminals.find((entry) => entry.id === id);
return terminal ? `${t("ide_side_panel.terminal_label")} ${terminal.number}` : t(sidePanelTab(id)?.labelKey ?? "");
};
- /** Where a tab's content sits: the whole area, one of the two columns, or nowhere. */
- const columnOf = (id: SidePanelTabId): SidePanelColumn | null => (id === active ? 0 : id === split ? 1 : null);
- const percent = `${splitRatio * 100}%`;
- const columnStyle = (column: SidePanelColumn | null): CSSProperties | undefined => {
- if (column === null || !split) return undefined;
- return column === 0 ? { left: 0, width: `calc(${percent} - 1px)` } : { left: `calc(${percent} + 1px)`, right: 0 };
- };
- const startSplitResize = (event: ReactPointerEvent<HTMLDivElement>) => {
- const box = content.current?.getBoundingClientRect();
- if (!box || event.button !== 0) return;
- event.preventDefault();
- event.currentTarget.setPointerCapture?.(event.pointerId);
- setResizingSplit(true);
- const move = (e: PointerEvent) => setSplitRatio((e.clientX - box.left) / box.width);
- const end = () => {
- setResizingSplit(false);
- window.removeEventListener("pointermove", move);
- window.removeEventListener("pointerup", end);
- window.removeEventListener("pointercancel", end);
- };
- window.addEventListener("pointermove", move);
- window.addEventListener("pointerup", end);
- window.addEventListener("pointercancel", end);
+ /** A tab's content box: its pane minus the title bar while split, the whole area otherwise. */
+ const boxOf = (id: SidePanelTabId) => {
+ const rect = rectOf.get(id);
+ if (!rect) return undefined;
+ return split ? paneBox(rect, "body") : undefined;
};
+ const shown = (id: SidePanelTabId) => rectOf.has(id);
+ const bodyClass = split ? "absolute min-h-0" : "absolute inset-0";
const registryAction = (tab: (typeof SIDE_PANEL_TABS)[number]): SurfaceAction => ({
id: tab.id, label: t(tab.labelKey), icon: tab.icon, shortcut: tab.shortcut, available: true,
isOpen: tabs.includes(tab.id), run: () => openTab(tab.id),
@@ -300,21 +299,22 @@ export function IdeSidePanel({ appearance, onScreen = true }: { appearance?: Ter
className="flex h-full min-h-0 flex-col overflow-hidden border-l border-border bg-card/40"
>
<div className="flex h-11 shrink-0 items-center gap-1 border-b border-border/60 px-2">
- <div role="tablist" aria-label={t("ide_side_panel.tabs_aria")} className="flex min-w-0 flex-1 items-center gap-1 overflow-x-auto">
+ <div ref={strip} role="tablist" aria-label={t("ide_side_panel.tabs_aria")}
+ data-detach-target={tabDrag.target?.kind === "detach" ? "true" : undefined}
+ className={cn("flex min-w-0 flex-1 items-center gap-1 overflow-x-auto rounded-lg transition-colors",
+ tabDrag.target?.kind === "detach" && "bg-accent/15 ring-1 ring-inset ring-accent")}>
{tabs.map((id) => {
const tab = sidePanelTab(id);
const terminal = terminals.find((entry) => entry.id === id);
if (!tab && !terminal) return null;
const label = tabLabel(id);
const Icon = tab?.icon ?? SquareTerminal;
- const column = columnOf(id);
- const selected = column !== null;
- // Split: both visible tabs are lit; the one a click would replace is lit fully.
- const focused = selected && (!split || column === focusedColumn);
+ const selected = shown(id);
+ // Split: every visible tab is lit; the one a click would replace is lit fully.
+ const focused = selected && id === active;
return (
<div
key={id}
- data-column={split && selected ? column : undefined}
className={cn(
"group/tab flex h-8 min-w-0 shrink-0 touch-none select-none items-center gap-1 rounded-lg pl-2.5 pr-1 text-sm transition-colors",
focused ? "bg-secondary text-foreground"
@@ -395,7 +395,7 @@ export function IdeSidePanel({ appearance, onScreen = true }: { appearance?: Ter
data-testid="ide-side-panel-split"
aria-label={t(split ? "ide_side_panel.unsplit" : "ide_side_panel.split")}
title={t(split ? "ide_side_panel.unsplit" : tabs.length > 1 ? "ide_side_panel.split" : "ide_side_panel.split_needs_two")}
- aria-pressed={!!split}
+ aria-pressed={split}
disabled={!split && tabs.length < 2}
onClick={toggleSplit}
className={cn(HEADER_BTN, split && "bg-secondary text-foreground")}
@@ -415,195 +415,67 @@ export function IdeSidePanel({ appearance, onScreen = true }: { appearance?: Ter
</button>
</div>
{/* Keyed by tab: Changes and Folder share one component and must not share its state. */}
- {/* Split, every tab sits in the column it was put in; the same element moves
- between whole area and column, so a browser page or a chat never reloads. */}
+ {/* Split, every tab sits in its pane; the same element moves between the
+ whole area and a pane, so a browser page or a chat never reloads. */}
<div ref={content} id={`${SIDE_PANEL_ID}-content`} role="tabpanel" data-testid="ide-side-panel-content"
- data-split={split ? "true" : undefined}
- className={cn("relative min-h-0 flex-1", resizingSplit && "cursor-col-resize select-none")}
+ data-split={split ? "true" : undefined} data-panes={split ? placed.leaves.length : undefined}
+ className="relative min-h-0 flex-1"
onPointerDownCapture={(event) => {
const box = content.current?.getBoundingClientRect();
- if (!split || !box || !box.width) return;
- setFocusedColumn((event.clientX - box.left) / box.width < splitRatio ? 0 : 1);
+ if (!split || !box || !box.width || !box.height) return;
+ const fx = (event.clientX - box.left) / box.width;
+ const fy = (event.clientY - box.top) / box.height;
+ const hit = placed.leaves.find(({ rect }) => fx >= rect.x && fx <= rect.x + rect.w && fy >= rect.y && fy <= rect.y + rect.h);
+ if (hit) focusPane(hit.leaf.id);
}}>
{open && tabs.length === 0 && <SurfaceLauncher actions={actions} keysEnabled={onScreen} />}
- {open && current && !current.keepAlive && (
- <div key={active} data-testid={`ide-side-panel-column-${active}`} className={split ? "absolute inset-y-0 min-h-0" : "h-full min-h-0"}
- style={columnStyle(0)}>{current.render()}</div>
- )}
- {open && split && sidePanelTab(split) && !sidePanelTab(split)!.keepAlive && (
- <div key={split} data-testid={`ide-side-panel-column-${split}`} className="absolute inset-y-0 min-h-0" style={columnStyle(1)}>
- {sidePanelTab(split)!.render()}
- </div>
- )}
+ {open && [...rectOf.keys()].map((id) => {
+ const tab = sidePanelTab(id);
+ if (!tab || tab.keepAlive || !tabs.includes(id)) return null;
+ return <div key={id} data-testid={`ide-side-panel-column-${id}`} className={cn(bodyClass, !split && "h-full")} style={boxOf(id)}>{tab.render()}</div>;
+ })}
{SIDE_PANEL_TABS.filter((tab) => tab.keepAlive && tabs.includes(tab.id)).map((tab) => (
- <div key={tab.id} hidden={!open || columnOf(tab.id) === null} data-testid={`ide-side-panel-column-${tab.id}`}
- className={split ? "absolute inset-y-0" : "absolute inset-0"} style={columnStyle(columnOf(tab.id))}>{tab.render()}</div>
+ <div key={tab.id} hidden={!open || !shown(tab.id)} data-testid={`ide-side-panel-column-${tab.id}`}
+ className={bodyClass} style={boxOf(tab.id)}>{tab.render()}</div>
))}
- {terminals.map((terminal) => <div key={terminal.id} hidden={!open || columnOf(terminal.id) === null}
- className={split ? "absolute inset-y-0" : "absolute inset-0"} style={columnStyle(columnOf(terminal.id))}
+ {terminals.map((terminal) => <div key={terminal.id} hidden={!open || !shown(terminal.id)}
+ className={bodyClass} style={boxOf(terminal.id)}
data-testid={`ide-side-panel-terminal-${terminal.id}`}>
{/* A terminal opened on a folder of the tree starts there; `folder` only
counts when no workspace id is named. */}
<WorkspaceTerminal paneKey={terminal.id} agentName="shell"
workspaceId={terminal.folder ? undefined : terminal.workspaceId} folder={terminal.folder}
title={`${t("ide_side_panel.terminal_label")} ${terminal.number} · ${terminal.workspaceName}`}
- active={onScreen && open && columnOf(terminal.id) !== null} appearance={appearance} />
+ active={onScreen && open && shown(terminal.id)} appearance={appearance} />
</div>)}
+ {open && split && placed.leaves.map((pane) => (
+ <PaneHeader
+ key={pane.leaf.id}
+ placed={pane}
+ label={tabLabel(pane.leaf.tab)}
+ icon={sidePanelTab(pane.leaf.tab)?.icon ?? SquareTerminal}
+ focused={pane.leaf.id === focusedPane}
+ onDragStart={(event) => tabDrag.start(event, pane.leaf.tab)}
+ onClick={() => { if (!tabDrag.consumeClick()) focusPane(pane.leaf.id); }}
+ onDetach={() => detachTab(pane.leaf.tab)}
+ onClose={() => closeTab(pane.leaf.tab)}
+ />
+ ))}
{open && split && (
- <>
- {/* Which column a tab click fills: a thin line over the focused one. */}
- <div aria-hidden className="pointer-events-none absolute top-0 z-10 h-0.5 bg-accent/70" style={columnStyle(focusedColumn)} />
- <div
- role="separator"
- aria-orientation="vertical"
- aria-label={t("ide_side_panel.split_resize")}
- aria-valuenow={Math.round(splitRatio * 100)}
- aria-valuemin={20}
- aria-valuemax={80}
- tabIndex={0}
- title={t("ide_side_panel.split_resize")}
- data-testid="ide-side-panel-split-resizer"
- onPointerDown={startSplitResize}
- onDoubleClick={() => setSplitRatio(DEFAULT_SPLIT_RATIO)}
- onKeyDown={(event) => {
- if (event.key === "ArrowLeft") setSplitRatio(splitRatio - 0.05);
- else if (event.key === "ArrowRight") setSplitRatio(splitRatio + 0.05);
- else return;
- event.preventDefault();
- }}
- className="group absolute inset-y-0 z-20 flex w-3 -translate-x-1/2 cursor-col-resize justify-center focus-visible:outline-none"
- style={{ left: percent }}
- >
- <div className={cn("h-full w-px bg-border transition-colors group-hover:bg-accent group-focus-visible:bg-accent",
- resizingSplit && "bg-accent")} />
- </div>
- </>
+ <SplitDividers dividers={placed.dividers} content={content} onResize={resizeSplit} onEvenOut={evenOutSplit}
+ label={t("ide_side_panel.split_resize")} />
)}
- {tabDrag.dragging && <TabDropZones column={tabDrag.target} ratio={split ? splitRatio : DEFAULT_SPLIT_RATIO} />}
+ {tabDrag.dragging && <DropPreview target={tabDrag.target} label={dropLabel} />}
</div>
{tabDrag.dragging && tabDrag.pointer && (
- <div aria-hidden className="pointer-events-none fixed z-50 rounded-md border border-border bg-popover px-2 py-1 text-xs font-medium text-foreground shadow-float"
+ <div aria-hidden data-testid="ide-side-panel-drag-ghost"
+ className="pointer-events-none fixed z-50 flex flex-col rounded-md border border-border bg-popover px-2 py-1 text-xs text-foreground shadow-float"
style={{ left: tabDrag.pointer.x + 12, top: tabDrag.pointer.y + 12 }}>
- {tabLabel(tabDrag.dragging)}
+ <span className="font-medium">{tabLabel(tabDrag.dragging)}</span>
+ {dropLabel && <span className="text-muted-foreground">{dropLabel}</span>}
</div>
)}
</aside>
);
}
-/**
- * The two halves a dragged tab can land on. Marked so the native browser window
- * steps aside while they show: it is drawn above the page and would hide them.
- */
-function TabDropZones({ column, ratio }: { column: SidePanelColumn | null; ratio: number }) {
- const t = useT();
- const zone = (which: SidePanelColumn) => (
- <div
- data-testid={`ide-side-panel-drop-${which === 0 ? "left" : "right"}`}
- data-over={column === which ? "true" : undefined}
- className={cn(
- "absolute inset-y-0 flex items-center justify-center p-2 transition-colors",
- column === which ? "bg-accent/15" : "bg-background/40",
- )}
- style={which === 0 ? { left: 0, width: `${ratio * 100}%` } : { left: `${ratio * 100}%`, right: 0 }}
- >
- <div className={cn(
- "flex h-full w-full items-center justify-center rounded-lg border-2 border-dashed text-sm font-medium transition-colors",
- column === which ? "border-accent text-foreground" : "border-border text-muted-foreground",
- )}>
- {t(which === 0 ? "ide_side_panel.drop_left" : "ide_side_panel.drop_right")}
- </div>
- </div>
- );
- return (
- <div data-hides-native-browser="" data-testid="ide-side-panel-drop-zones" className="pointer-events-none absolute inset-0 z-30 backdrop-blur-[1px]">
- {zone(0)}
- {zone(1)}
- </div>
- );
-}
-
-/**
- * Drag a tab out of the strip onto the left or right half of the panel to see
- * it beside another one. Pointer events rather than HTML drag and drop: those
- * would arm the file drop targets of the terminals, and a release outside the
- * window would never be heard.
- */
-function useTabDrag(
- content: RefObject<HTMLDivElement | null>,
- ratio: number,
- onDrop: (id: SidePanelTabId, column: SidePanelColumn) => void,
-) {
- const [dragging, setDragging] = useState<SidePanelTabId | null>(null);
- const [target, setTarget] = useState<SidePanelColumn | null>(null);
- const [pointer, setPointer] = useState<{ x: number; y: number } | null>(null);
- const swallowClick = useRef(false);
- const cleanupRef = useRef<(() => void) | null>(null);
- const ratioRef = useRef(ratio);
- ratioRef.current = ratio;
- const dropRef = useRef(onDrop);
- dropRef.current = onDrop;
-
- useEffect(() => () => cleanupRef.current?.(), []);
-
- const start = (event: ReactPointerEvent<HTMLElement>, id: SidePanelTabId) => {
- if (event.button !== 0) return;
- cleanupRef.current?.();
- const origin = { x: event.clientX, y: event.clientY };
- let active = false;
- let over: SidePanelColumn | null = null;
- const columnAt = (x: number, y: number): SidePanelColumn | null => {
- const box = content.current?.getBoundingClientRect();
- if (!box || x < box.left || x > box.right || y < box.top || y > box.bottom || !box.width) return null;
- return (x - box.left) / box.width < ratioRef.current ? 0 : 1;
- };
- const move = (e: PointerEvent) => {
- if (!active) {
- if (Math.hypot(e.clientX - origin.x, e.clientY - origin.y) < TAB_DRAG_SLOP_PX) return;
- active = true;
- setDragging(id);
- }
- over = columnAt(e.clientX, e.clientY);
- setTarget(over);
- setPointer({ x: e.clientX, y: e.clientY });
- };
- const finish = (drop: boolean) => {
- cleanupRef.current?.();
- if (!active) return;
- swallowClick.current = true;
- // The click that follows a drag must not also select the tab.
- window.setTimeout(() => { swallowClick.current = false; }, 0);
- setDragging(null);
- setTarget(null);
- setPointer(null);
- if (drop && over !== null) dropRef.current(id, over);
- };
- const up = () => finish(true);
- const cancel = () => finish(false);
- const key = (e: KeyboardEvent) => { if (e.key === "Escape") finish(false); };
- window.addEventListener("pointermove", move);
- window.addEventListener("pointerup", up);
- window.addEventListener("pointercancel", cancel);
- window.addEventListener("keydown", key);
- cleanupRef.current = () => {
- cleanupRef.current = null;
- window.removeEventListener("pointermove", move);
- window.removeEventListener("pointerup", up);
- window.removeEventListener("pointercancel", cancel);
- window.removeEventListener("keydown", key);
- };
- };
-
- return {
- dragging,
- target,
- pointer,
- start,
- /** True once for the click a finished drag leaves behind. */
- consumeClick: () => {
- const swallow = swallowClick.current;
- swallowClick.current = false;
- return swallow;
- },
- };
-}
diff --git a/dodaios/ui/web/frontend/src/components/agentic/sidePanel/sidePanelSplit.tsx b/dodaios/ui/web/frontend/src/components/agentic/sidePanel/sidePanelSplit.tsx
new file mode 100644
index 0000000000..f502096359
--- /dev/null
+++ b/dodaios/ui/web/frontend/src/components/agentic/sidePanel/sidePanelSplit.tsx
@@ -0,0 +1,332 @@
+import { useEffect, useRef, useState, type CSSProperties, type PointerEvent as ReactPointerEvent, type RefObject } from "react";
+import { GripVertical, Minus, X, type LucideIcon } from "lucide-react";
+import { useT } from "@/i18n";
+import { cn } from "@/lib/utils";
+import type { SidePanelTabId } from "@/store/ideSidePanel";
+import { zoneAt, type DropZone, type LayoutRect, type PlacedDivider, type PlacedLeaf } from "@/store/sidePanelLayout";
+
+/** Height of the title bar each pane wears while the panel is split. */
+export const PANE_HEADER_PX = 28;
+/** How far a pressed tab must travel before it counts as dragged rather than clicked. */
+const DRAG_SLOP_PX = 6;
+
+/** Where a dragged tab would land if released now. */
+export type DragTarget =
+ | { kind: "pane"; paneId: string | null; zone: DropZone; rect: LayoutRect }
+ /** Back onto the tab strip, or anywhere outside the panel: out of the split. */
+ | { kind: "detach" };
+
+const pct = (share: number) => `${(share * 100).toFixed(4)}%`;
+const touchesStart = (start: number) => start > 0.0005;
+const touchesEnd = (start: number, size: number) => start + size < 0.9995;
+
+/**
+ * Pane rectangle → CSS box inside the content area. Neighbouring panes keep a
+ * 1px seam between them for the divider line; `header` reserves the title bar.
+ */
+export function paneBox(rect: LayoutRect, part: "body" | "header" | "whole"): CSSProperties {
+ const left = touchesStart(rect.x) ? 1 : 0;
+ const right = touchesEnd(rect.x, rect.w) ? 1 : 0;
+ const top = touchesStart(rect.y) ? 1 : 0;
+ const bottom = touchesEnd(rect.y, rect.h) ? 1 : 0;
+ const box: CSSProperties = {
+ left: `calc(${pct(rect.x)} + ${left}px)`,
+ width: `calc(${pct(rect.w)} - ${left + right}px)`,
+ };
+ if (part === "header") return { ...box, top: `calc(${pct(rect.y)} + ${top}px)`, height: PANE_HEADER_PX };
+ const headerPx = part === "body" ? PANE_HEADER_PX : 0;
+ return { ...box, top: `calc(${pct(rect.y)} + ${top + headerPx}px)`, height: `calc(${pct(rect.h)} - ${top + bottom + headerPx}px)` };
+}
+
+/** The part of a pane a drop on `zone` fills, for the preview. */
+function zoneRect(rect: LayoutRect, zone: DropZone): LayoutRect {
+ const { x, y, w, h } = rect;
+ switch (zone) {
+ case "left": return { x, y, w: w / 2, h };
+ case "right": return { x: x + w / 2, y, w: w / 2, h };
+ case "top": return { x, y, w, h: h / 2 };
+ case "bottom": return { x, y: y + h / 2, w, h: h / 2 };
+ default: return rect;
+ }
+}
+
+interface DragOptions {
+ content: RefObject<HTMLElement | null>;
+ strip: RefObject<HTMLElement | null>;
+ /** Panes on screen; one pane with a null id while the panel is unsplit. */
+ panes: { id: string | null; rect: LayoutRect }[];
+ /** Whether a drop on an edge may add a pane for this tab. */
+ canSplit: (id: SidePanelTabId) => boolean;
+ /** Whether this tab sits in a pane of a split (only those can be taken out). */
+ inSplit: (id: SidePanelTabId) => boolean;
+ onDrop: (id: SidePanelTabId, target: DragTarget) => void;
+}
+
+/**
+ * Drag a tab (from the strip or by a pane's title bar) onto a pane: an edge
+ * splits it, the middle shows the tab there or swaps two panes. Dragging a
+ * tab of a split back onto the strip, or out of the panel, takes it out of
+ * the split. Pointer events rather than HTML drag and drop: those would arm
+ * the file drop targets of the terminals, and a release outside the window
+ * would never be heard.
+ */
+export function useTabDrag(options: DragOptions) {
+ const [dragging, setDragging] = useState<SidePanelTabId | null>(null);
+ const [target, setTarget] = useState<DragTarget | null>(null);
+ const [pointer, setPointer] = useState<{ x: number; y: number } | null>(null);
+ const swallowClick = useRef(false);
+ const cleanupRef = useRef<(() => void) | null>(null);
+ const optionsRef = useRef(options);
+ optionsRef.current = options;
+
+ useEffect(() => () => cleanupRef.current?.(), []);
+
+ const targetAt = (id: SidePanelTabId, x: number, y: number): DragTarget | null => {
+ const { content, strip, panes, canSplit, inSplit } = optionsRef.current;
+ const stripBox = strip.current?.getBoundingClientRect();
+ const inside = (box: DOMRect | undefined) => !!box && box.width > 0 && x >= box.left && x <= box.right && y >= box.top && y <= box.bottom;
+ if (inside(stripBox)) return inSplit(id) ? { kind: "detach" } : null;
+ const box = content.current?.getBoundingClientRect();
+ if (!box || !inside(box)) return inSplit(id) ? { kind: "detach" } : null;
+ const fx = (x - box.left) / box.width;
+ const fy = (y - box.top) / box.height;
+ const pane = panes.find(({ rect }) => fx >= rect.x && fx <= rect.x + rect.w && fy >= rect.y && fy <= rect.y + rect.h);
+ if (!pane) return null;
+ const zone = zoneAt((fx - pane.rect.x) / pane.rect.w, (fy - pane.rect.y) / pane.rect.h, canSplit(id));
+ return { kind: "pane", paneId: pane.id, zone, rect: pane.rect };
+ };
+
+ const start = (event: ReactPointerEvent<HTMLElement>, id: SidePanelTabId) => {
+ if (event.button !== 0) return;
+ cleanupRef.current?.();
+ const origin = { x: event.clientX, y: event.clientY };
+ let active = false;
+ let over: DragTarget | null = null;
+ const move = (e: PointerEvent) => {
+ if (!active) {
+ if (Math.hypot(e.clientX - origin.x, e.clientY - origin.y) < DRAG_SLOP_PX) return;
+ active = true;
+ setDragging(id);
+ }
+ over = targetAt(id, e.clientX, e.clientY);
+ setTarget(over);
+ setPointer({ x: e.clientX, y: e.clientY });
+ };
+ const finish = (drop: boolean) => {
+ cleanupRef.current?.();
+ if (!active) return;
+ swallowClick.current = true;
+ // The click that follows a drag must not also select the tab.
+ window.setTimeout(() => { swallowClick.current = false; }, 0);
+ setDragging(null);
+ setTarget(null);
+ setPointer(null);
+ if (drop && over) optionsRef.current.onDrop(id, over);
+ };
+ const up = () => finish(true);
+ const cancel = () => finish(false);
+ const key = (e: KeyboardEvent) => { if (e.key === "Escape") finish(false); };
+ window.addEventListener("pointermove", move);
+ window.addEventListener("pointerup", up);
+ window.addEventListener("pointercancel", cancel);
+ window.addEventListener("keydown", key);
+ cleanupRef.current = () => {
+ cleanupRef.current = null;
+ window.removeEventListener("pointermove", move);
+ window.removeEventListener("pointerup", up);
+ window.removeEventListener("pointercancel", cancel);
+ window.removeEventListener("keydown", key);
+ };
+ };
+
+ return {
+ dragging,
+ target,
+ pointer,
+ start,
+ /** True once for the click a finished drag leaves behind. */
+ consumeClick: () => {
+ const swallow = swallowClick.current;
+ swallowClick.current = false;
+ return swallow;
+ },
+ };
+}
+
+const ZONE_LABEL: Record<Exclude<DropZone, "center">, string> = {
+ left: "ide_side_panel.drop_left",
+ right: "ide_side_panel.drop_right",
+ top: "ide_side_panel.drop_top",
+ bottom: "ide_side_panel.drop_bottom",
+};
+
+/** What releasing the drag would do, in words. */
+export function useDropLabel(target: DragTarget | null, swaps: boolean): string | null {
+ const t = useT();
+ if (!target) return null;
+ if (target.kind === "detach") return t("ide_side_panel.drop_detach");
+ if (target.zone === "center") return t(swaps ? "ide_side_panel.drop_swap" : "ide_side_panel.drop_here");
+ return t(ZONE_LABEL[target.zone]);
+}
+
+/**
+ * The area a drop would fill, drawn over the panes while a tab is dragged.
+ * Marked so the native browser window steps aside: it is drawn above the page
+ * and would hide the preview.
+ */
+export function DropPreview({ target, label }: { target: DragTarget | null; label: string | null }) {
+ const area = target?.kind === "pane" ? zoneRect(target.rect, target.zone) : null;
+ return (
+ <div data-hides-native-browser="" data-testid="ide-side-panel-drop-zones" className="pointer-events-none absolute inset-0 z-30 bg-background/30">
+ {area && target?.kind === "pane" && (
+ <div
+ data-testid={`ide-side-panel-drop-${target.zone}`}
+ className="absolute p-1.5 transition-all duration-100"
+ style={{ left: pct(area.x), top: pct(area.y), width: pct(area.w), height: pct(area.h) }}
+ >
+ <div className="flex h-full w-full items-center justify-center rounded-lg border-2 border-dashed border-accent bg-accent/15 text-sm font-medium text-foreground">
+ {label}
+ </div>
+ </div>
+ )}
+ </div>
+ );
+}
+
+/** The grips between panes; dragging one moves only the two panes it divides. */
+export function SplitDividers({ dividers, content, onResize, onEvenOut, label }: {
+ dividers: PlacedDivider[];
+ content: RefObject<HTMLElement | null>;
+ onResize: (splitId: string, index: number, share: number) => void;
+ onEvenOut: (splitId: string) => void;
+ label: string;
+}) {
+ const [resizing, setResizing] = useState<string | null>(null);
+ const start = (event: ReactPointerEvent<HTMLDivElement>, divider: PlacedDivider) => {
+ const box = content.current?.getBoundingClientRect();
+ if (!box || event.button !== 0) return;
+ event.preventDefault();
+ event.stopPropagation();
+ event.currentTarget.setPointerCapture?.(event.pointerId);
+ const key = `${divider.splitId}:${divider.index}`;
+ setResizing(key);
+ const { splitRect, direction } = divider;
+ const move = (e: PointerEvent) => {
+ const share = direction === "row"
+ ? ((e.clientX - box.left) / box.width - splitRect.x) / splitRect.w
+ : ((e.clientY - box.top) / box.height - splitRect.y) / splitRect.h;
+ if (Number.isFinite(share)) onResize(divider.splitId, divider.index, share);
+ };
+ const end = () => {
+ setResizing(null);
+ window.removeEventListener("pointermove", move);
+ window.removeEventListener("pointerup", end);
+ window.removeEventListener("pointercancel", end);
+ };
+ window.addEventListener("pointermove", move);
+ window.addEventListener("pointerup", end);
+ window.addEventListener("pointercancel", end);
+ };
+ return (
+ <>
+ {dividers.map((divider) => {
+ const key = `${divider.splitId}:${divider.index}`;
+ const row = divider.direction === "row";
+ const { rect } = divider;
+ return (
+ <div
+ key={key}
+ role="separator"
+ aria-orientation={row ? "vertical" : "horizontal"}
+ aria-label={label}
+ title={label}
+ tabIndex={0}
+ data-testid={`ide-side-panel-divider-${divider.index}-${divider.direction}`}
+ onPointerDown={(event) => start(event, divider)}
+ onDoubleClick={() => onEvenOut(divider.splitId)}
+ onKeyDown={(event) => {
+ const step = (row ? ["ArrowLeft", "ArrowRight"] : ["ArrowUp", "ArrowDown"]).indexOf(event.key);
+ if (step < 0) return;
+ event.preventDefault();
+ const span = row ? divider.splitRect.w : divider.splitRect.h;
+ const origin = row ? divider.splitRect.x : divider.splitRect.y;
+ onResize(divider.splitId, divider.index, (divider.at - origin) / span + (step ? 0.05 : -0.05));
+ }}
+ className={cn(
+ "group absolute z-20 flex justify-center focus-visible:outline-none",
+ row ? "w-3 -translate-x-1/2 cursor-col-resize" : "h-3 -translate-y-1/2 cursor-row-resize flex-col",
+ )}
+ style={row
+ ? { left: pct(rect.x), top: pct(rect.y), height: pct(rect.h) }
+ : { top: pct(rect.y), left: pct(rect.x), width: pct(rect.w) }}
+ >
+ <div className={cn(
+ "bg-border transition-colors group-hover:bg-accent group-focus-visible:bg-accent",
+ row ? "h-full w-px" : "h-px w-full",
+ resizing === key && "bg-accent",
+ )} />
+ </div>
+ );
+ })}
+ {/* While a divider moves, nothing under the pointer (a terminal, the browser) may take it. */}
+ {resizing && <div data-hides-native-browser="" className={cn("absolute inset-0 z-10", resizing && "cursor-grabbing")} />}
+ </>
+ );
+}
+
+/** The title bar of one pane in a split: drag it to move the pane, or take it out. */
+export function PaneHeader({ placed, label, icon: Icon, focused, onDragStart, onClick, onDetach, onClose }: {
+ placed: PlacedLeaf<SidePanelTabId>;
+ label: string;
+ icon: LucideIcon;
+ focused: boolean;
+ onDragStart: (event: ReactPointerEvent<HTMLElement>) => void;
+ onClick: () => void;
+ onDetach: () => void;
+ onClose: () => void;
+}) {
+ const t = useT();
+ return (
+ <div
+ data-testid={`ide-side-panel-pane-header-${placed.leaf.tab}`}
+ data-focused={focused ? "true" : undefined}
+ className={cn(
+ "absolute z-10 flex touch-none select-none items-center gap-1.5 border-b px-1.5 text-xs",
+ focused ? "border-accent/70 text-foreground" : "border-border/60 text-muted-foreground",
+ )}
+ style={paneBox(placed.rect, "header")}
+ >
+ <div
+ role="button"
+ tabIndex={-1}
+ title={t("ide_side_panel.pane_drag")}
+ onPointerDown={onDragStart}
+ onClick={onClick}
+ className="flex min-w-0 flex-1 cursor-grab items-center gap-1.5 active:cursor-grabbing"
+ >
+ <GripVertical className="h-3.5 w-3.5 shrink-0 opacity-60" aria-hidden />
+ <Icon className="h-3.5 w-3.5 shrink-0" aria-hidden />
+ <span className="truncate font-medium">{label}</span>
+ </div>
+ <button
+ type="button"
+ data-testid={`ide-side-panel-pane-detach-${placed.leaf.tab}`}
+ aria-label={`${t("ide_side_panel.pane_detach")}: ${label}`}
+ title={t("ide_side_panel.pane_detach")}
+ onClick={onDetach}
+ className="inline-flex h-5 w-5 shrink-0 items-center justify-center rounded hover:bg-secondary hover:text-foreground"
+ >
+ <Minus className="h-3.5 w-3.5" aria-hidden />
+ </button>
+ <button
+ type="button"
+ aria-label={`${t("ide_side_panel.close_tab")}: ${label}`}
+ title={t("ide_side_panel.close_tab")}
+ onClick={onClose}
+ className="inline-flex h-5 w-5 shrink-0 items-center justify-center rounded hover:bg-secondary hover:text-foreground"
+ >
+ <X className="h-3.5 w-3.5" aria-hidden />
+ </button>
+ </div>
+ );
+}
diff --git a/dodaios/ui/web/frontend/src/i18n/locales/de.json b/dodaios/ui/web/frontend/src/i18n/locales/de.json
index f0d62581f2..c2867640e8 100644
--- a/dodaios/ui/web/frontend/src/i18n/locales/de.json
+++ b/dodaios/ui/web/frontend/src/i18n/locales/de.json
@@ -7626,7 +7626,14 @@
"split_resize": "Ziehen, um die Spalten anzupassen (Doppelklick setzt zurück)",
"drop_left": "Links öffnen",
"drop_right": "Rechts öffnen",
- "drag_hint": "Auf die linke oder rechte Hälfte ziehen, um zwei Tabs nebeneinander zu sehen",
+ "drop_top": "Oben öffnen",
+ "drop_bottom": "Unten öffnen",
+ "drop_swap": "Bereiche tauschen",
+ "drop_here": "Hier anzeigen",
+ "drop_detach": "Loslassen, um es aus der Teilung zu lösen",
+ "pane_detach": "Aus der Teilung lösen (bleibt als Tab offen)",
+ "pane_drag": "Ziehen, um diesen Bereich zu verschieben, zu tauschen oder herauszulösen",
+ "drag_hint": "Auf einen Bereich ziehen: Rand teilt, Mitte tauscht. Herausziehen löst die Teilung.",
"expand": "Seitenleiste öffnen",
"collapse": "Seitenleiste schließen",
"resize": "Breite der Seitenleiste ändern",
diff --git a/dodaios/ui/web/frontend/src/i18n/locales/en.json b/dodaios/ui/web/frontend/src/i18n/locales/en.json
index 39890201ab..39449927b1 100644
--- a/dodaios/ui/web/frontend/src/i18n/locales/en.json
+++ b/dodaios/ui/web/frontend/src/i18n/locales/en.json
@@ -7626,7 +7626,14 @@
"split_resize": "Drag to resize the columns (double-click resets)",
"drop_left": "Open on the left",
"drop_right": "Open on the right",
- "drag_hint": "Drag onto the left or right half to see two tabs side by side",
+ "drop_top": "Open above",
+ "drop_bottom": "Open below",
+ "drop_swap": "Swap panes",
+ "drop_here": "Show here",
+ "drop_detach": "Release to take it out of the split",
+ "pane_detach": "Take out of the split (stays open as a tab)",
+ "pane_drag": "Drag to move, swap or take out this pane",
+ "drag_hint": "Drag onto a pane: an edge splits it, the middle swaps. Drag out to unsplit.",
"expand": "Open side panel",
"collapse": "Close side panel",
"resize": "Resize side panel",
diff --git a/dodaios/ui/web/frontend/src/i18n/locales/es.json b/dodaios/ui/web/frontend/src/i18n/locales/es.json
index 12e39e1ef4..edb45fdb89 100644
--- a/dodaios/ui/web/frontend/src/i18n/locales/es.json
+++ b/dodaios/ui/web/frontend/src/i18n/locales/es.json
@@ -7626,7 +7626,14 @@
"split_resize": "Arrastra para ajustar las columnas (doble clic restablece)",
"drop_left": "Abrir a la izquierda",
"drop_right": "Abrir a la derecha",
- "drag_hint": "Arrastra a la mitad izquierda o derecha para ver dos pestañas lado a lado",
+ "drop_top": "Abrir arriba",
+ "drop_bottom": "Abrir abajo",
+ "drop_swap": "Intercambiar paneles",
+ "drop_here": "Mostrar aquí",
+ "drop_detach": "Suelta para sacarlo de la división",
+ "pane_detach": "Sacar de la división (sigue abierta como pestaña)",
+ "pane_drag": "Arrastra para mover, intercambiar o sacar este panel",
+ "drag_hint": "Arrastra sobre un panel: un borde lo divide, el centro intercambia. Arrastra fuera para deshacer la división.",
"expand": "Abrir panel lateral",
"collapse": "Cerrar panel lateral",
"resize": "Cambiar el ancho del panel lateral",
diff --git a/dodaios/ui/web/frontend/src/i18n/locales/pt.json b/dodaios/ui/web/frontend/src/i18n/locales/pt.json
index 089f67ed80..af8ec29bd9 100644
--- a/dodaios/ui/web/frontend/src/i18n/locales/pt.json
+++ b/dodaios/ui/web/frontend/src/i18n/locales/pt.json
@@ -7626,7 +7626,14 @@
"split_resize": "Arraste para ajustar as colunas (clique duplo redefine)",
"drop_left": "Abrir à esquerda",
"drop_right": "Abrir à direita",
- "drag_hint": "Arraste para a metade esquerda ou direita para ver duas abas lado a lado",
+ "drop_top": "Abrir acima",
+ "drop_bottom": "Abrir abaixo",
+ "drop_swap": "Trocar painéis",
+ "drop_here": "Mostrar aqui",
+ "drop_detach": "Solte para tirá-lo da divisão",
+ "pane_detach": "Tirar da divisão (continua aberta como aba)",
+ "pane_drag": "Arraste para mover, trocar ou tirar este painel",
+ "drag_hint": "Arraste sobre um painel: uma borda divide, o centro troca. Arraste para fora para desfazer a divisão.",
"expand": "Abrir painel lateral",
"collapse": "Fechar painel lateral",
"resize": "Redimensionar painel lateral",
diff --git a/dodaios/ui/web/frontend/src/i18n/locales/zh.json b/dodaios/ui/web/frontend/src/i18n/locales/zh.json
index 89c2d221d6..73dcfb3b1c 100644
--- a/dodaios/ui/web/frontend/src/i18n/locales/zh.json
+++ b/dodaios/ui/web/frontend/src/i18n/locales/zh.json
@@ -7626,7 +7626,14 @@
"split_resize": "拖动以调整列宽(双击重置)",
"drop_left": "在左侧打开",
"drop_right": "在右侧打开",
- "drag_hint": "拖到左半边或右半边,即可并排查看两个标签页",
+ "drop_top": "在上方打开",
+ "drop_bottom": "在下方打开",
+ "drop_swap": "交换窗格",
+ "drop_here": "在此显示",
+ "drop_detach": "松开即可移出分屏",
+ "pane_detach": "移出分屏(仍作为标签页保留)",
+ "pane_drag": "拖动以移动、交换或移出此窗格",
+ "drag_hint": "拖到窗格上:边缘分屏,中间交换。拖出即可取消分屏。",
"expand": "打开侧边面板",
"collapse": "关闭侧边面板",
"resize": "调整侧边面板大小",
diff --git a/dodaios/ui/web/frontend/src/store/ideSidePanel.ts b/dodaios/ui/web/frontend/src/store/ideSidePanel.ts
index 1884db8e9e..dde739017c 100644
--- a/dodaios/ui/web/frontend/src/store/ideSidePanel.ts
+++ b/dodaios/ui/web/frontend/src/store/ideSidePanel.ts
@@ -1,4 +1,20 @@
import { create } from "zustand";
+import {
+ MAX_PANES,
+ evenOut,
+ findLeaf,
+ findLeafByTab,
+ insertBeside,
+ leaf,
+ leaves,
+ parseLayout,
+ prune,
+ removeLeaf,
+ replaceTab,
+ resizeAt,
+ type DropZone,
+ type LayoutNode,
+} from "./sidePanelLayout";
/**
* The Agentic IDE's right-hand side panel: open or shut, which tabs it holds,
@@ -40,18 +56,11 @@ const OPEN_KEY = "jarvis.agenticIde.sidePanelOpen";
// every tab they had ever added.
const TABS_KEY = "jarvis.agenticIde.sidePanelTabs.v5";
-const SPLIT_KEY = "jarvis.agenticIde.sidePanelSplit.v1";
+const LAYOUT_KEY = "jarvis.agenticIde.sidePanelLayout.v1";
const DEFAULT_TABS: SidePanelTabId[] = [];
-/** Share of the panel the first column takes while two tabs sit side by side. */
-export const DEFAULT_SPLIT_RATIO = 0.5;
-export const MIN_SPLIT_RATIO = 0.2;
-export const MAX_SPLIT_RATIO = 0.8;
-/** The two columns of a split panel: 0 holds `active`, 1 holds `split`. */
-export type SidePanelColumn = 0 | 1;
-
-const clampRatio = (value: number) => Math.min(MAX_SPLIT_RATIO, Math.max(MIN_SPLIT_RATIO, value));
+export type SidePanelLayout = LayoutNode<SidePanelTabId>;
/** Stand-in for `active` while no tab is open; the panel then shows the launcher. */
const NO_TAB: SidePanelTabId = "agents";
@@ -66,26 +75,31 @@ function storedOpen(): boolean {
}
}
-function storedSplit(tabs: SidePanelTabId[], active: SidePanelTabId): { split: SidePanelTabId | null; splitRatio: number } {
+function storedLayout(tabs: SidePanelTabId[]): { layout: SidePanelLayout | null; focusedPane: string | null } {
try {
- const raw = JSON.parse(localStorage.getItem(SPLIT_KEY) ?? "null") as { split?: unknown; ratio?: unknown } | null;
- const ratio = typeof raw?.ratio === "number" && Number.isFinite(raw.ratio) ? clampRatio(raw.ratio) : DEFAULT_SPLIT_RATIO;
- const split = isTabId(raw?.split) && tabs.includes(raw.split) && raw.split !== active ? raw.split : null;
- return { split, splitRatio: ratio };
+ const raw = JSON.parse(localStorage.getItem(LAYOUT_KEY) ?? "null") as { layout?: unknown; focused?: unknown } | null;
+ const layout = keepTwo(prune(parseLayout(raw?.layout, isTabId), (tab) => tabs.includes(tab)));
+ const focused = typeof raw?.focused === "string" && findLeaf(layout, raw.focused) ? raw.focused : leaves(layout)[0]?.id ?? null;
+ return { layout, focusedPane: focused };
} catch {
- return { split: null, splitRatio: DEFAULT_SPLIT_RATIO };
+ return { layout: null, focusedPane: null };
}
}
-function persistSplit(split: SidePanelTabId | null, ratio: number): void {
+function persistLayout(layout: SidePanelLayout | null, focusedPane: string | null): void {
try {
- // A shell does not survive a reload, so a split onto one is not kept either.
- localStorage.setItem(SPLIT_KEY, JSON.stringify({ split: split && isTabId(split) ? split : null, ratio }));
+ // A shell does not survive a reload, so its pane is not kept either.
+ localStorage.setItem(LAYOUT_KEY, JSON.stringify({ layout: keepTwo(prune(layout, isTabId)), focused: focusedPane }));
} catch {
/* a convenience only */
}
}
+/** One pane left is no split: the panel then shows that tab alone. */
+function keepTwo(layout: SidePanelLayout | null): SidePanelLayout | null {
+ return leaves(layout).length >= 2 ? layout : null;
+}
+
function storedTabs(): { tabs: SidePanelTabId[]; active: SidePanelTabId } {
try {
const raw = JSON.parse(localStorage.getItem(TABS_KEY) ?? "null") as {
@@ -130,26 +144,27 @@ interface IdeSidePanelState {
addTerminalTab: (workspaceId: string, workspaceName: string, folder?: string) => void;
setOpen: (open: boolean) => void;
/**
- * Second tab shown beside `active` (the panel split into two columns), or
- * null for one tab at a time.
+ * Several tabs on screen at once: a tree of panes, side by side and on top
+ * of each other. Null shows `active` alone. Persisted.
*/
- split: SidePanelTabId | null;
- /** Width share of the first column while split. Persisted. */
- splitRatio: number;
- setSplitRatio: (ratio: number) => void;
- /** Column a tab click or a newly opened tab goes to while split. */
- focusedColumn: SidePanelColumn;
- setFocusedColumn: (column: SidePanelColumn) => void;
+ layout: SidePanelLayout | null;
+ /** Pane a tab click fills; its tab is `active`. */
+ focusedPane: string | null;
+ focusPane: (paneId: string) => void;
/**
- * Show `id` in `column`, splitting the panel when it was not. The other
- * column keeps what it showed; when that was `id` itself, the neighbouring
- * tab fills it. No-op with a single tab open.
+ * A tab dropped on a pane. `center` shows it there (two visible tabs trade
+ * places); an edge splits that pane and puts the tab beside it, moving it
+ * out of its old pane. `paneId` null means the unsplit panel.
*/
- splitWith: (id: SidePanelTabId, column: SidePanelColumn) => void;
- /** Split the panel with the tab next to the one in front, or join it back. */
+ dropTab: (id: SidePanelTabId, paneId: string | null, zone: DropZone) => void;
+ /** Take a tab out of the split; it stays open in the strip. */
+ detachTab: (id: SidePanelTabId) => void;
+ /** Split with the tab next to the one in front, or back to one tab. */
toggleSplit: () => void;
- /** Back to one tab: the focused column's tab stays in front. */
- unsplit: () => void;
+ /** Move divider `index` of split `splitId` to `share` of that split. */
+ resizeSplit: (splitId: string, index: number, share: number) => void;
+ /** Give every pane of split `splitId` the same size. */
+ evenOutSplit: (splitId: string) => void;
/** Open a tab (or bring it forward when it is already open). */
openTab: (id: SidePanelTabId) => void;
select: (id: SidePanelTabId) => void;
@@ -174,7 +189,7 @@ interface IdeSidePanelState {
}
const initialTabs = storedTabs();
-const initialSplit = storedSplit(initialTabs.tabs, initialTabs.active);
+const initialLayout = storedLayout(initialTabs.tabs);
/** The tab beside `id` in the strip: the next one, else the previous one. */
function neighbour(tabs: SidePanelTabId[], id: SidePanelTabId): SidePanelTabId | null {
@@ -183,26 +198,30 @@ function neighbour(tabs: SidePanelTabId[], id: SidePanelTabId): SidePanelTabId |
}
export const useIdeSidePanelStore = create<IdeSidePanelState>((set, get) => {
- const commit = (next: Partial<Pick<IdeSidePanelState, "open" | "tabs" | "active" | "split">>) => {
- const merged = { open: get().open, tabs: get().tabs, active: get().active, split: get().split, ...next };
- if (merged.split && (merged.split === merged.active || !merged.tabs.includes(merged.split))) merged.split = null;
- set(merged.split ? merged : { ...merged, focusedColumn: 0 });
+ type Committed = Pick<IdeSidePanelState, "open" | "tabs" | "active" | "layout" | "focusedPane">;
+ const commit = (next: Partial<Committed>) => {
+ const merged: Committed = {
+ open: get().open, tabs: get().tabs, active: get().active, layout: get().layout, focusedPane: get().focusedPane, ...next,
+ };
+ merged.layout = keepTwo(prune(merged.layout, (tab) => merged.tabs.includes(tab)));
+ if (merged.layout) {
+ const focused = findLeaf(merged.layout, merged.focusedPane ?? "") ?? leaves(merged.layout)[0];
+ merged.focusedPane = focused.id;
+ merged.active = focused.tab;
+ } else {
+ merged.focusedPane = null;
+ }
+ set(merged);
persist(merged.open, merged.tabs, merged.active);
- persistSplit(merged.split, get().splitRatio);
+ persistLayout(merged.layout, merged.focusedPane);
};
- /** Bring an open tab into view: into the focused column while split. */
+ /** Bring an open tab into view: into the focused pane while split. */
const show = (id: SidePanelTabId, tabs: SidePanelTabId[]) => {
- const { split, active, focusedColumn } = get();
- if (!split) return commit({ open: true, tabs, active: id });
- if (id === active) {
- set({ focusedColumn: 0 });
- return commit({ open: true, tabs });
- }
- if (id === split) {
- set({ focusedColumn: 1 });
- return commit({ open: true, tabs });
- }
- commit(focusedColumn === 1 ? { open: true, tabs, split: id } : { open: true, tabs, active: id });
+ const { layout, focusedPane } = get();
+ if (!layout) return commit({ open: true, tabs, active: id });
+ const visible = findLeafByTab(layout, id);
+ if (visible) return commit({ open: true, tabs, focusedPane: visible.id });
+ commit({ open: true, tabs, layout: replaceTab(layout, focusedPane ?? "", id) });
};
return {
open: storedOpen(),
@@ -229,38 +248,64 @@ export const useIdeSidePanelStore = create<IdeSidePanelState>((set, get) => {
if (!open) set({ spotlight: null, maximized: false, inUse: false });
commit({ open });
},
- split: initialSplit.split,
- splitRatio: initialSplit.splitRatio,
- setSplitRatio: (ratio) => {
- const splitRatio = clampRatio(ratio);
- set({ splitRatio });
- persistSplit(get().split, splitRatio);
+ layout: initialLayout.layout,
+ focusedPane: initialLayout.focusedPane,
+ focusPane: (paneId) => {
+ if (get().focusedPane !== paneId && findLeaf(get().layout, paneId)) commit({ focusedPane: paneId });
},
- focusedColumn: 0,
- setFocusedColumn: (column) => { if (get().split && get().focusedColumn !== column) set({ focusedColumn: column }); },
- splitWith: (id, column) => {
- const { tabs, active, split } = get();
+ dropTab: (id, paneId, zone) => {
+ const { tabs, active, layout } = get();
if (!tabs.includes(id)) return;
- const first: SidePanelTabId | null = active;
- const second: SidePanelTabId | null = split ?? (active === id ? neighbour(tabs, id) : active);
- // The column that does not get `id` keeps its tab; if it held `id`, the
- // two trade places (or the neighbour steps in when there was no split).
- const other = column === 0 ? (second === id ? first : second) : (first === id ? second : first);
- if (!other || other === id) return;
- set({ focusedColumn: column });
- commit(column === 0 ? { open: true, active: id, split: other } : { open: true, active: other, split: id });
+ if (!layout) {
+ if (zone === "center") return show(id, tabs);
+ // The tab in front dropped on its own edge: its neighbour fills the other side.
+ const other = id === active ? neighbour(tabs, id) : active;
+ if (!other) return;
+ const base = leaf(other);
+ const added = leaf(id);
+ return commit({ open: true, layout: insertBeside(base, base.id, id, zone, added), focusedPane: added.id });
+ }
+ const target = findLeaf(layout, paneId ?? "");
+ if (!target) return;
+ const source = findLeafByTab(layout, id);
+ if (source?.id === target.id) return commit({ focusedPane: target.id });
+ if (zone === "center") {
+ // Two visible tabs trade places; a hidden one takes the pane over.
+ let next = replaceTab(layout, target.id, id);
+ if (source) next = replaceTab(next, source.id, target.tab);
+ return commit({ open: true, layout: next, focusedPane: target.id });
+ }
+ if (!source && leaves(layout).length >= MAX_PANES) return;
+ const added = leaf(id);
+ const rest = source ? removeLeaf(layout, source.id) : layout;
+ const next = rest ? insertBeside(rest, target.id, id, zone, added) : null;
+ commit({ open: true, layout: next, focusedPane: added.id });
+ },
+ detachTab: (id) => {
+ const { layout, focusedPane } = get();
+ const pane = findLeafByTab(layout, id);
+ if (!layout || !pane) return;
+ const next = removeLeaf(layout, pane.id);
+ const remaining = leaves(next);
+ if (!keepTwo(next)) return commit({ layout: null, active: remaining[0]?.tab ?? get().active });
+ commit({ layout: next, focusedPane: focusedPane === pane.id ? remaining[0].id : focusedPane });
},
toggleSplit: () => {
- const { split, tabs, active } = get();
- if (split) return get().unsplit();
+ const { layout, tabs, active } = get();
+ if (layout) return commit({ layout: null, active });
const other = neighbour(tabs, active);
- if (other) get().splitWith(other, 1);
+ if (!other) return;
+ const base = leaf(active);
+ const added = leaf(other);
+ commit({ open: true, layout: insertBeside(base, base.id, other, "right", added), focusedPane: added.id });
},
- unsplit: () => {
- const { split, active, focusedColumn } = get();
- if (!split) return;
- commit({ active: focusedColumn === 1 ? split : active, split: null });
+ resizeSplit: (splitId, index, share) => {
+ const next = resizeAt(get().layout, splitId, index, share);
+ if (next === get().layout) return;
+ set({ layout: next });
+ persistLayout(next, get().focusedPane);
},
+ evenOutSplit: (splitId) => commit({ layout: evenOut(get().layout, splitId) }),
openTab: (id) => {
const { tabs } = get();
show(id, tabs.includes(id) ? tabs : [...tabs, id]);
@@ -269,14 +314,16 @@ export const useIdeSidePanelStore = create<IdeSidePanelState>((set, get) => {
if (get().tabs.includes(id)) show(id, get().tabs);
},
closeTab: (id) => {
- const { tabs, active, split } = get();
+ const { tabs, active, layout } = get();
const index = tabs.indexOf(id);
if (index < 0) return;
const rest = tabs.filter((tab) => tab !== id);
set({ terminals: get().terminals.filter((terminal) => terminal.id !== id) });
- // Closing either half of a split leaves the other half in front, alone.
- if (split && id === split) return commit({ tabs: rest, split: null });
- if (split && id === active) return commit({ tabs: rest, active: split, split: null });
+ // A tab on screen in a split takes its pane with it; the others close up.
+ if (layout && findLeafByTab(layout, id)) {
+ const next = removeLeaf(layout, findLeafByTab(layout, id)!.id);
+ return commit({ tabs: rest, layout: next, active: keepTwo(next) ? active : leaves(next)[0]?.tab ?? active });
+ }
if (rest.length === 0) {
set({ spotlight: null, maximized: false });
commit({ tabs: DEFAULT_TABS, active: NO_TAB });
diff --git a/dodaios/ui/web/frontend/src/store/sidePanelLayout.test.ts b/dodaios/ui/web/frontend/src/store/sidePanelLayout.test.ts
new file mode 100644
index 0000000000..47e74e5065
--- /dev/null
+++ b/dodaios/ui/web/frontend/src/store/sidePanelLayout.test.ts
@@ -0,0 +1,92 @@
+import { describe, expect, it } from "vitest";
+import {
+ columnCount,
+ insertBeside,
+ leaf,
+ leaves,
+ normalize,
+ parseLayout,
+ placeLayout,
+ prune,
+ removeLeaf,
+ resizeAt,
+ zoneAt,
+ type LayoutNode,
+} from "./sidePanelLayout";
+
+const tabsOf = (node: LayoutNode | null) => leaves(node).map((entry) => entry.tab);
+const isTab = (value: unknown): value is string => typeof value === "string";
+
+describe("side panel layout", () => {
+ it("splits a pane and shares the slot with a sibling in the same direction", () => {
+ const a = leaf("a", "A");
+ let tree: LayoutNode = insertBeside(a, "A", "b", "right", leaf("b", "B"));
+ expect(tree).toMatchObject({ kind: "split", direction: "row", sizes: [0.5, 0.5] });
+ tree = insertBeside(tree, "B", "c", "right", leaf("c", "C"));
+ // Flat: three panes in one row, C taking half of B's slot.
+ expect(tree).toMatchObject({ kind: "split", direction: "row", sizes: [0.5, 0.25, 0.25] });
+ expect(tabsOf(tree)).toEqual(["a", "b", "c"]);
+ tree = insertBeside(tree, "A", "d", "top", leaf("d", "D"));
+ expect(tabsOf(tree)).toEqual(["d", "a", "b", "c"]);
+ expect(columnCount(tree)).toBe(3);
+ });
+
+ it("closes up when a pane goes and drops the split at one pane", () => {
+ let tree: LayoutNode | null = insertBeside(insertBeside(leaf("a", "A"), "A", "b", "right", leaf("b", "B")), "B", "c", "bottom", leaf("c", "C"));
+ tree = removeLeaf(tree, "C");
+ expect(tree).toMatchObject({ kind: "split", direction: "row" });
+ expect(tabsOf(tree)).toEqual(["a", "b"]);
+ tree = removeLeaf(tree, "A");
+ expect(tree).toMatchObject({ kind: "leaf", tab: "b" });
+ });
+
+ it("flattens a split nested in one of the same direction", () => {
+ const inner: LayoutNode = { kind: "split", id: "i", direction: "row", children: [leaf("b", "B"), leaf("c", "C")], sizes: [0.5, 0.5] };
+ const outer: LayoutNode = { kind: "split", id: "o", direction: "row", children: [leaf("a", "A"), inner], sizes: [0.5, 0.5] };
+ expect(normalize(outer)).toMatchObject({ children: [{ id: "A" }, { id: "B" }, { id: "C" }], sizes: [0.5, 0.25, 0.25] });
+ });
+
+ it("moves a divider between two panes only, within limits", () => {
+ const tree = insertBeside(insertBeside(leaf("a", "A"), "A", "b", "right", leaf("b", "B")), "B", "c", "right", leaf("c", "C"));
+ const id = (tree as { id: string }).id;
+ const moved = resizeAt(tree, id, 1, 0.8);
+ expect((moved as { sizes: number[] }).sizes.map((size) => Math.round(size * 100))).toEqual([50, 30, 20]);
+ const clamped = resizeAt(tree, id, 0, 0);
+ expect((clamped as { sizes: number[] }).sizes[0]).toBeCloseTo(0.1);
+ });
+
+ it("places panes and dividers in shares of the area", () => {
+ const tree = insertBeside(insertBeside(leaf("a", "A"), "A", "b", "right", leaf("b", "B")), "B", "c", "bottom", leaf("c", "C"));
+ const { leaves: placed, dividers } = placeLayout(tree);
+ expect(placed.map(({ leaf: entry, rect }) => [entry.tab, rect])).toEqual([
+ ["a", { x: 0, y: 0, w: 0.5, h: 1 }],
+ ["b", { x: 0.5, y: 0, w: 0.5, h: 0.5 }],
+ ["c", { x: 0.5, y: 0.5, w: 0.5, h: 0.5 }],
+ ]);
+ expect(dividers.map((divider) => [divider.direction, divider.at])).toEqual([["row", 0.5], ["column", 0.5]]);
+ });
+
+ it("reads the drop zone from the pointer's place in a pane", () => {
+ expect(zoneAt(0.5, 0.5, true)).toBe("center");
+ expect(zoneAt(0.05, 0.5, true)).toBe("left");
+ expect(zoneAt(0.95, 0.4, true)).toBe("right");
+ expect(zoneAt(0.5, 0.1, true)).toBe("top");
+ expect(zoneAt(0.4, 0.9, true)).toBe("bottom");
+ expect(zoneAt(0.05, 0.5, false)).toBe("center");
+ });
+
+ it("drops stored layouts that are malformed, and panes of closed or repeated tabs", () => {
+ expect(parseLayout({ kind: "split", id: "x", direction: "diagonal", children: [], sizes: [] }, isTab)).toBeNull();
+ expect(parseLayout("nope", isTab)).toBeNull();
+ const stored = { kind: "split", id: "s", direction: "row", sizes: [1, 1, 1], children: [
+ { kind: "leaf", id: "A", tab: "a" }, { kind: "leaf", id: "B", tab: "b" }, { kind: "leaf", id: "C", tab: 7 },
+ ] };
+ const parsed = parseLayout(stored, isTab);
+ expect(tabsOf(parsed)).toEqual(["a", "b"]);
+ expect(tabsOf(prune(parsed, (tab) => tab !== "b"))).toEqual(["a"]);
+ const twice = { kind: "split", id: "s", direction: "row", sizes: [1, 1], children: [
+ { kind: "leaf", id: "A", tab: "a" }, { kind: "leaf", id: "B", tab: "a" },
+ ] };
+ expect(tabsOf(prune(parseLayout(twice, isTab), () => true))).toEqual(["a"]);
+ });
+});
diff --git a/dodaios/ui/web/frontend/src/store/sidePanelLayout.ts b/dodaios/ui/web/frontend/src/store/sidePanelLayout.ts
new file mode 100644
index 0000000000..5cb26c2010
--- /dev/null
+++ b/dodaios/ui/web/frontend/src/store/sidePanelLayout.ts
@@ -0,0 +1,285 @@
+/**
+ * The side panel's split layout: a tree of panes, each showing one open tab.
+ *
+ * A `row` lays its children out left to right, a `column` top to bottom.
+ * `sizes` are the children's shares of the parent (they sum to 1). Every
+ * function here is pure and returns a normalized tree: no split with a single
+ * child, no split directly inside a split of the same direction, and `null`
+ * once only one pane is left (the panel then shows one tab, unsplit).
+ */
+
+export type SplitDirection = "row" | "column";
+/** Where a dragged tab lands on a pane: one of its edges, or the pane itself. */
+export type DropZone = "left" | "right" | "top" | "bottom" | "center";
+
+export interface LayoutLeaf<T extends string = string> {
+ kind: "leaf";
+ id: string;
+ tab: T;
+}
+
+export interface LayoutSplit<T extends string = string> {
+ kind: "split";
+ id: string;
+ direction: SplitDirection;
+ children: LayoutNode<T>[];
+ sizes: number[];
+}
+
+export type LayoutNode<T extends string = string> = LayoutLeaf<T> | LayoutSplit<T>;
+
+/** More panes than this would leave each one too small to use. */
+export const MAX_PANES = 6;
+/** No pane shrinks below this share of its split when the dividers move. */
+export const MIN_PANE_SHARE = 0.1;
+
+let counter = 0;
+export const newNodeId = (prefix: string) => `${prefix}${Date.now().toString(36)}${(counter++).toString(36)}`;
+
+export const leaf = <T extends string>(tab: T, id = newNodeId("p")): LayoutLeaf<T> => ({ kind: "leaf", id, tab });
+
+export function leaves<T extends string>(node: LayoutNode<T> | null): LayoutLeaf<T>[] {
+ if (!node) return [];
+ return node.kind === "leaf" ? [node] : node.children.flatMap((child) => leaves(child));
+}
+
+export const findLeafByTab = <T extends string>(node: LayoutNode<T> | null, tab: T) =>
+ leaves(node).find((entry) => entry.tab === tab) ?? null;
+
+export const findLeaf = <T extends string>(node: LayoutNode<T> | null, id: string) =>
+ leaves(node).find((entry) => entry.id === id) ?? null;
+
+const normalizeSizes = (sizes: number[]): number[] => {
+ const total = sizes.reduce((sum, size) => sum + (size > 0 ? size : 0), 0);
+ if (!total) return sizes.map(() => 1 / sizes.length);
+ return sizes.map((size) => (size > 0 ? size : 0) / total);
+};
+
+/** Collapse single-child splits, flatten same-direction nesting, fix the sizes. */
+export function normalize<T extends string>(node: LayoutNode<T> | null): LayoutNode<T> | null {
+ if (!node || node.kind === "leaf") return node;
+ const children: LayoutNode<T>[] = [];
+ const sizes: number[] = [];
+ node.children.forEach((child, index) => {
+ const normal = normalize(child);
+ if (!normal) return;
+ const share = node.sizes[index] ?? 1 / node.children.length;
+ if (normal.kind === "split" && normal.direction === node.direction) {
+ normal.children.forEach((grandchild, inner) => {
+ children.push(grandchild);
+ sizes.push(share * normal.sizes[inner]);
+ });
+ } else {
+ children.push(normal);
+ sizes.push(share);
+ }
+ });
+ if (children.length === 0) return null;
+ if (children.length === 1) return children[0];
+ return { ...node, children, sizes: normalizeSizes(sizes) };
+}
+
+/** The tree with `leafId` removed; its share goes to its siblings. */
+export function removeLeaf<T extends string>(node: LayoutNode<T> | null, leafId: string): LayoutNode<T> | null {
+ const strip = (current: LayoutNode<T>): LayoutNode<T> | null => {
+ if (current.kind === "leaf") return current.id === leafId ? null : current;
+ const kept: LayoutNode<T>[] = [];
+ const sizes: number[] = [];
+ current.children.forEach((child, index) => {
+ const next = strip(child);
+ if (next) {
+ kept.push(next);
+ sizes.push(current.sizes[index]);
+ }
+ });
+ return { ...current, children: kept, sizes };
+ };
+ return node ? normalize(strip(node)) : null;
+}
+
+const directionOf = (zone: DropZone): SplitDirection => (zone === "left" || zone === "right" ? "row" : "column");
+const before = (zone: DropZone) => zone === "left" || zone === "top";
+
+/** The tree with a new pane for `tab` on the `zone` edge of `targetId`. */
+export function insertBeside<T extends string>(
+ node: LayoutNode<T>,
+ targetId: string,
+ tab: T,
+ zone: Exclude<DropZone, "center">,
+ newLeaf: LayoutLeaf<T> = leaf(tab),
+): LayoutNode<T> {
+ const direction = directionOf(zone);
+ const place = (current: LayoutNode<T>): LayoutNode<T> => {
+ if (current.kind === "leaf") {
+ if (current.id !== targetId) return current;
+ return {
+ kind: "split",
+ id: newNodeId("s"),
+ direction,
+ children: before(zone) ? [newLeaf, current] : [current, newLeaf],
+ sizes: [0.5, 0.5],
+ };
+ }
+ const index = current.children.findIndex((child) => child.kind === "leaf" && child.id === targetId);
+ // A sibling in a split of the same direction: share the target's slot.
+ if (index >= 0 && current.direction === direction) {
+ const half = current.sizes[index] / 2;
+ const children = [...current.children];
+ const sizes = [...current.sizes];
+ const at = before(zone) ? index : index + 1;
+ sizes[index] = half;
+ children.splice(at, 0, newLeaf);
+ sizes.splice(at, 0, half);
+ return { ...current, children, sizes };
+ }
+ return { ...current, children: current.children.map(place) };
+ };
+ return normalize(place(node)) ?? newLeaf;
+}
+
+export const replaceTab = <T extends string>(node: LayoutNode<T> | null, leafId: string, tab: T): LayoutNode<T> | null => {
+ const swap = (current: LayoutNode<T>): LayoutNode<T> =>
+ current.kind === "leaf"
+ ? (current.id === leafId ? { ...current, tab } : current)
+ : { ...current, children: current.children.map(swap) };
+ return node ? swap(node) : null;
+};
+
+/** Drop every pane whose tab `keep` refuses (a closed tab, a shell of another window). */
+export function prune<T extends string>(node: LayoutNode<T> | null, keep: (tab: T) => boolean): LayoutNode<T> | null {
+ let next = node;
+ const seen = new Set<T>();
+ for (const entry of leaves(node)) {
+ if (!keep(entry.tab) || seen.has(entry.tab)) next = removeLeaf(next, entry.id);
+ seen.add(entry.tab);
+ }
+ return next;
+}
+
+/** Move the divider between child `index` and `index + 1` of split `splitId` to `share` of the split. */
+export function resizeAt<T extends string>(node: LayoutNode<T> | null, splitId: string, index: number, share: number): LayoutNode<T> | null {
+ const walk = (current: LayoutNode<T>): LayoutNode<T> => {
+ if (current.kind === "leaf") return current;
+ if (current.id !== splitId) return { ...current, children: current.children.map(walk) };
+ const start = current.sizes.slice(0, index).reduce((sum, size) => sum + size, 0);
+ const pair = current.sizes[index] + current.sizes[index + 1];
+ const first = Math.min(pair - MIN_PANE_SHARE, Math.max(MIN_PANE_SHARE, share - start));
+ if (!(pair > 2 * MIN_PANE_SHARE)) return current;
+ const sizes = [...current.sizes];
+ sizes[index] = first;
+ sizes[index + 1] = pair - first;
+ return { ...current, sizes };
+ };
+ return node ? walk(node) : null;
+}
+
+/** Even out the panes of split `splitId` (a divider's double-click). */
+export function evenOut<T extends string>(node: LayoutNode<T> | null, splitId: string): LayoutNode<T> | null {
+ const walk = (current: LayoutNode<T>): LayoutNode<T> =>
+ current.kind === "leaf" ? current
+ : current.id === splitId ? { ...current, sizes: current.children.map(() => 1 / current.children.length) }
+ : { ...current, children: current.children.map(walk) };
+ return node ? walk(node) : null;
+}
+
+/** A rectangle in shares of the whole panel area (0..1). */
+export interface LayoutRect {
+ x: number;
+ y: number;
+ w: number;
+ h: number;
+}
+
+export interface PlacedLeaf<T extends string = string> {
+ leaf: LayoutLeaf<T>;
+ rect: LayoutRect;
+}
+
+export interface PlacedDivider {
+ splitId: string;
+ /** Index of the child before the divider. */
+ index: number;
+ direction: SplitDirection;
+ /** The divider line: x (row) or y (column) in panel shares, and its extent. */
+ at: number;
+ rect: LayoutRect;
+ /** The split's own rectangle, to turn a pointer position into a share. */
+ splitRect: LayoutRect;
+}
+
+/** Where every pane and every divider sits, in shares of the panel area. */
+export function placeLayout<T extends string>(node: LayoutNode<T> | null): { leaves: PlacedLeaf<T>[]; dividers: PlacedDivider[] } {
+ const placed: PlacedLeaf<T>[] = [];
+ const dividers: PlacedDivider[] = [];
+ const walk = (current: LayoutNode<T>, rect: LayoutRect) => {
+ if (current.kind === "leaf") {
+ placed.push({ leaf: current, rect });
+ return;
+ }
+ let offset = 0;
+ current.children.forEach((child, index) => {
+ const share = current.sizes[index];
+ const childRect = current.direction === "row"
+ ? { x: rect.x + rect.w * offset, y: rect.y, w: rect.w * share, h: rect.h }
+ : { x: rect.x, y: rect.y + rect.h * offset, w: rect.w, h: rect.h * share };
+ walk(child, childRect);
+ offset += share;
+ if (index < current.children.length - 1) {
+ const at = current.direction === "row" ? rect.x + rect.w * offset : rect.y + rect.h * offset;
+ dividers.push({
+ splitId: current.id,
+ index,
+ direction: current.direction,
+ at,
+ rect: current.direction === "row" ? { x: at, y: rect.y, w: 0, h: rect.h } : { x: rect.x, y: at, w: rect.w, h: 0 },
+ splitRect: rect,
+ });
+ }
+ });
+ };
+ if (node) walk(node, { x: 0, y: 0, w: 1, h: 1 });
+ return { leaves: placed, dividers };
+}
+
+/** How many panes sit side by side at the widest point, to size the panel. */
+export function columnCount(node: LayoutNode | null): number {
+ if (!node || node.kind === "leaf") return 1;
+ const counts = node.children.map(columnCount);
+ return node.direction === "row" ? counts.reduce((sum, count) => sum + count, 0) : Math.max(...counts);
+}
+
+/** The zone of a pane under a pointer at (`fx`, `fy`) in shares of that pane. */
+export function zoneAt(fx: number, fy: number, canSplit: boolean): DropZone {
+ if (!canSplit) return "center";
+ const dx = Math.min(fx, 1 - fx);
+ const dy = Math.min(fy, 1 - fy);
+ if (Math.min(dx, dy) > 0.25) return "center";
+ if (dx <= dy) return fx < 0.5 ? "left" : "right";
+ return fy < 0.5 ? "top" : "bottom";
+}
+
+/** Shape check for a stored layout; anything off is dropped rather than trusted. */
+export function parseLayout<T extends string>(raw: unknown, isTab: (value: unknown) => value is T): LayoutNode<T> | null {
+ const parse = (value: unknown, depth: number): LayoutNode<T> | null => {
+ if (!value || typeof value !== "object" || depth > 8) return null;
+ const node = value as Record<string, unknown>;
+ if (typeof node.id !== "string") return null;
+ if (node.kind === "leaf") return isTab(node.tab) ? { kind: "leaf", id: node.id, tab: node.tab } : null;
+ if (node.kind !== "split" || (node.direction !== "row" && node.direction !== "column")) return null;
+ const rawSizes = node.sizes;
+ if (!Array.isArray(node.children) || !Array.isArray(rawSizes) || node.children.length !== rawSizes.length) return null;
+ const children: LayoutNode<T>[] = [];
+ const sizes: number[] = [];
+ node.children.forEach((child, index) => {
+ const parsed = parse(child, depth + 1);
+ const size = Number(rawSizes[index]);
+ if (parsed && Number.isFinite(size) && size > 0) {
+ children.push(parsed);
+ sizes.push(size);
+ }
+ });
+ return { kind: "split", id: node.id, direction: node.direction, children, sizes };
+ };
+ const tree = normalize(parse(raw, 0));
+ return leaves(tree).length > MAX_PANES ? null : tree;
+}