|
1 | 1 | import { consume } from "@lit/context"; |
2 | 2 | import { html, nothing } from "lit"; |
3 | | -import { property } from "lit/decorators.js"; |
| 3 | +import { property, state as litState } from "lit/decorators.js"; |
4 | 4 | import type { |
5 | 5 | TaskSuggestion, |
6 | 6 | TaskSuggestionEvent, |
@@ -133,6 +133,18 @@ const CHAT_SPACE_ACTIVATION_SELECTOR = |
133 | 133 | "a[href], button, summary, [role='button'], [role='checkbox'], [role='link'], [role='radio'], [role='switch']"; |
134 | 134 | const CHAT_MODAL_SELECTOR = "dialog[open], [aria-modal='true']"; |
135 | 135 |
|
| 136 | +/* Pane-width thresholds (CSS px). Split panes and compact windows can be far |
| 137 | + * narrower than the viewport, so side-by-side layouts key off the pane's own |
| 138 | + * measured width, never viewport media queries. */ |
| 139 | +// Side rail (230-280px) plus a readable thread; below this the rail docks bottom. |
| 140 | +const WORKSPACE_RAIL_SIDE_MIN_PANE_WIDTH = 800; |
| 141 | +// Widest the rail's grid column gets; a side-docked rail takes this from the |
| 142 | +// width available to the chat + detail-panel split. |
| 143 | +const WORKSPACE_RAIL_MAX_WIDTH = 280; |
| 144 | +// .chat-main min-width (312) + divider + .chat-sidebar min-width (300) + slack; |
| 145 | +// below this the detail panel stacks under the thread. |
| 146 | +const DETAIL_SIDEBAR_SIDE_MIN_WIDTH = 680; |
| 147 | + |
136 | 148 | const NEW_SESSION_ACTIVE_RUN_MESSAGE = |
137 | 149 | "Start a new session after the active run or queued messages finish."; |
138 | 150 | const NEW_SESSION_LIST_LOADING_MESSAGE = |
@@ -174,6 +186,10 @@ class ChatPane extends OpenClawLightDomElement { |
174 | 186 |
|
175 | 187 | private readonly chatState = new ChatStateController<ChatPageHost>(this); |
176 | 188 | private state: ChatPageHost | undefined; |
| 189 | + /* Infinity until the first ResizeObserver tick so an unmeasured pane keeps |
| 190 | + * the wide side-by-side layout instead of flashing the stacked one. */ |
| 191 | + @litState() private paneWidth = Number.POSITIVE_INFINITY; |
| 192 | + private paneResizeObserver: ResizeObserver | null = null; |
177 | 193 | private connectedClient: GatewayBrowserClient | null = null; |
178 | 194 | private connectionGeneration = 0; |
179 | 195 | private nativeDraftCleanup: (() => void) | null = null; |
@@ -809,6 +825,16 @@ class ChatPane extends OpenClawLightDomElement { |
809 | 825 |
|
810 | 826 | override connectedCallback() { |
811 | 827 | super.connectedCallback(); |
| 828 | + if (typeof ResizeObserver === "function") { |
| 829 | + this.paneResizeObserver = new ResizeObserver((entries) => { |
| 830 | + const width = entries.at(-1)?.contentRect.width; |
| 831 | + // Hidden panes (narrow split view) report 0; keep the last real width. |
| 832 | + if (typeof width === "number" && width > 0 && width !== this.paneWidth) { |
| 833 | + this.paneWidth = width; |
| 834 | + } |
| 835 | + }); |
| 836 | + this.paneResizeObserver.observe(this); |
| 837 | + } |
812 | 838 | this.addEventListener("pointerdown", this.handlePaneFocus); |
813 | 839 | this.addEventListener("focusin", this.handlePaneFocus); |
814 | 840 | document.addEventListener("keydown", this.handleDocumentKeydown, true); |
@@ -915,6 +941,8 @@ class ChatPane extends OpenClawLightDomElement { |
915 | 941 | } |
916 | 942 |
|
917 | 943 | override disconnectedCallback() { |
| 944 | + this.paneResizeObserver?.disconnect(); |
| 945 | + this.paneResizeObserver = null; |
918 | 946 | this.connectionGeneration += 1; |
919 | 947 | this.taskSuggestionsRequestVersion += 1; |
920 | 948 | this.taskSuggestions = []; |
@@ -1189,12 +1217,22 @@ class ChatPane extends OpenClawLightDomElement { |
1189 | 1217 | const canOpenRealtimeTalkSettings = hasOperatorAdminAccess( |
1190 | 1218 | this.context.gateway.snapshot.hello?.auth ?? null, |
1191 | 1219 | ); |
1192 | | - const sessionWorkspace = createSessionWorkspaceProps(state); |
| 1220 | + const sessionWorkspace = createSessionWorkspaceProps(state, { |
| 1221 | + narrowLayout: this.paneWidth < WORKSPACE_RAIL_SIDE_MIN_PANE_WIDTH, |
| 1222 | + }); |
1193 | 1223 | const backgroundTasks = createBackgroundTasksProps(state, { |
1194 | 1224 | onOpenSession: (sessionKey) => { |
1195 | 1225 | this.onPaneSessionChange?.(this.paneId, sessionKey); |
1196 | 1226 | }, |
1197 | 1227 | }); |
| 1228 | + const railSideDocked = |
| 1229 | + !sessionWorkspace.collapsed && |
| 1230 | + !sessionWorkspace.narrowLayout && |
| 1231 | + sessionWorkspace.dock !== "bottom"; |
| 1232 | + // Every open side rail (workspace and/or background tasks) narrows the |
| 1233 | + // room left for the chat + detail split. |
| 1234 | + const sideRailCount = (railSideDocked ? 1 : 0) + (backgroundTasks.collapsed ? 0 : 1); |
| 1235 | + const detailSplitWidth = this.paneWidth - sideRailCount * WORKSPACE_RAIL_MAX_WIDTH; |
1198 | 1236 | const props: ChatProps = { |
1199 | 1237 | paneId: this.paneId, |
1200 | 1238 | sessionKey: state.sessionKey, |
@@ -1405,6 +1443,7 @@ class ChatPane extends OpenClawLightDomElement { |
1405 | 1443 | }, |
1406 | 1444 | sidebarOpen: state.sidebarOpen, |
1407 | 1445 | sidebarContent: state.sidebarContent, |
| 1446 | + sidebarStacked: detailSplitWidth < DETAIL_SIDEBAR_SIDE_MIN_WIDTH, |
1408 | 1447 | splitRatio: state.splitRatio, |
1409 | 1448 | canvasPluginSurfaceUrl: state.hello?.pluginSurfaceUrls?.canvas ?? null, |
1410 | 1449 | onOpenSidebar: state.handleOpenSidebar, |
|
0 commit comments