The tablet ran the phone layout with a half-finished iPad draft on top: two custom sidebars, a leftover overflow menu, split Files/Changes header buttons, and phone-width sheets stretched across a 13" screen. This brings it onto the phone's navigation model and keeps only the differences a large screen earns. - Sessions are a persistent resizable left sidebar; the overflow menu is gone and its destinations moved into that sidebar's footer (connected instance, settings, pending web update) and into the workspace drawer. - The workspace (Changes / Files / Terminal / Notes / MCP) is the phone's drawer everywhere: a resizable right sidebar where the screen can host one (up to 900px) and the full-cover drawer otherwise, with its mounted panes — an open diff, an edited file, an attached terminal — surviving rotation. - Header dropdowns are anchored popovers: the recents switcher mirrors the usage overlay on the left, and its trigger is sized to the title rather than to the free width. - App-level pages (settings, instances, update, an opened plan) render as centered dialogs instead of covering the screen. - Overlays center on the chat column through published insets, so the model and directory pickers no longer sit off-centre; the directory picker also stops overriding the shared width clamp. - Wide chat layout applies to mobile surfaces, where a tablet chat column is finally wide enough for the setting to mean anything. The layout gate is a live size class rather than a device check, so Android tablets and foldables are covered by the same code: - `enabled` when the shortest viewport side is at le sw600dp). The short side is what makes this a size question instead of a device question — a phone reports ~360-430 whichev unfolded book foldable ~600+, and folding shut drops back under it. iPads also answer on identity, since iPadOS hands out od - `roomyForPanels` when landscape and at least 1000px wide, which is what it takes to host the sidebar, the panel and a readabl foldables miss it in BOTH orientations — their long side is barely wider than a tablet's short one — so they keep the portr Every consumer re-decides instead of remembering wha open sidebar closes if the device folds shut under it. iPad behaviour is unchanged: its landscape widths all clear the panel ones do not, exactly as the previous orientation check did. Hardware keyboards are read natively. iOS reports them through GCKeyboard, published to the web layer at document start and kep disconnect and foregrounding; the layer stops inferring once that answers. A single early publish was not enough — the connect no already-attached keyboard fires before the page exists, and GameController can populate late — so the state is re-published across resume. With a keyboard attached the draft screen keeps its starter chips and the composer never collapses; tablets skip the colla Runtimes with no native answer fall back to inferring it from the keyboard bridge, and only ever conclude "hardware" from silen Also: sidebar rows no longer sit on a differently ti footer is no longer clipped by an over-tall content box, the resize handles moved above the panes' own overlays so they can actu now-unreachable overflow menu, fullscreen terminal/MCP/notes surfaces and their locale key are deleted. Device behaviour is unverified — the tablet layout, keyboard bridge and the foldable size class have not been exercised on hardware, and the 600/1000 thresholds are derived fr rather than measured on a foldable.
98 lines
3.6 KiB
TypeScript
98 lines
3.6 KiB
TypeScript
import React from 'react';
|
|
|
|
export const IPAD_LEFT_SIDEBAR_WIDTH = 320;
|
|
export const IPAD_RIGHT_SIDEBAR_WIDTH = 380;
|
|
const IPAD_SIDEBAR_MIN_WIDTH = 280;
|
|
const IPAD_SIDEBAR_MAX_WIDTH = 560;
|
|
/** The workspace panel holds diffs, a file editor and a terminal, so it earns
|
|
far more room than the sessions list ever needs. */
|
|
export const IPAD_WORKSPACE_SIDEBAR_MAX_WIDTH = 900;
|
|
|
|
/** Drag-resize for the iPad sidebars: same live-width mechanics as the desktop
|
|
Sidebar (imperative styles during the drag, committed to state at the end),
|
|
but with a finger-sized grab strip instead of a 3px hover handle. */
|
|
export function useIpadSidebarResize(
|
|
side: 'left' | 'right',
|
|
storageKey: string,
|
|
defaultWidth: number,
|
|
maxWidth: number = IPAD_SIDEBAR_MAX_WIDTH,
|
|
) {
|
|
const asideRef = React.useRef<HTMLElement | null>(null);
|
|
const [width, setWidth] = React.useState(() => {
|
|
if (typeof window === 'undefined') return defaultWidth;
|
|
const stored = Number.parseInt(window.localStorage.getItem(storageKey) ?? '', 10);
|
|
if (!Number.isFinite(stored)) return defaultWidth;
|
|
return Math.min(maxWidth, Math.max(IPAD_SIDEBAR_MIN_WIDTH, stored));
|
|
});
|
|
const [isResizing, setIsResizing] = React.useState(false);
|
|
const startXRef = React.useRef(0);
|
|
const startWidthRef = React.useRef(width);
|
|
const liveWidthRef = React.useRef<number | null>(null);
|
|
const pointerIdRef = React.useRef<number | null>(null);
|
|
|
|
const clampWidth = React.useCallback((value: number) => (
|
|
Math.min(maxWidth, Math.max(IPAD_SIDEBAR_MIN_WIDTH, Math.round(value)))
|
|
), [maxWidth]);
|
|
|
|
const applyLiveWidth = React.useCallback((nextWidth: number) => {
|
|
const aside = asideRef.current;
|
|
if (!aside) return;
|
|
aside.style.width = `${nextWidth}px`;
|
|
aside.style.minWidth = `${nextWidth}px`;
|
|
aside.style.maxWidth = `${nextWidth}px`;
|
|
aside.style.setProperty('--oc-ipad-sidebar-width', `${nextWidth}px`);
|
|
}, []);
|
|
|
|
const handlePointerDown = React.useCallback((event: React.PointerEvent) => {
|
|
try {
|
|
event.currentTarget.setPointerCapture(event.pointerId);
|
|
} catch {
|
|
// ignore
|
|
}
|
|
pointerIdRef.current = event.pointerId;
|
|
startXRef.current = event.clientX;
|
|
startWidthRef.current = width;
|
|
liveWidthRef.current = width;
|
|
setIsResizing(true);
|
|
event.preventDefault();
|
|
}, [width]);
|
|
|
|
const handlePointerMove = React.useCallback((event: React.PointerEvent) => {
|
|
if (pointerIdRef.current !== event.pointerId) return;
|
|
const delta = event.clientX - startXRef.current;
|
|
const next = clampWidth(startWidthRef.current + (side === 'left' ? delta : -delta));
|
|
if (liveWidthRef.current === next) return;
|
|
liveWidthRef.current = next;
|
|
applyLiveWidth(next);
|
|
}, [applyLiveWidth, clampWidth, side]);
|
|
|
|
const handlePointerEnd = React.useCallback((event: React.PointerEvent) => {
|
|
if (pointerIdRef.current !== event.pointerId) return;
|
|
try {
|
|
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
} catch {
|
|
// ignore
|
|
}
|
|
const finalWidth = clampWidth(liveWidthRef.current ?? startWidthRef.current);
|
|
pointerIdRef.current = null;
|
|
liveWidthRef.current = null;
|
|
setIsResizing(false);
|
|
setWidth(finalWidth);
|
|
try {
|
|
window.localStorage.setItem(storageKey, String(finalWidth));
|
|
} catch {
|
|
// ignore
|
|
}
|
|
}, [clampWidth, storageKey]);
|
|
|
|
const handleProps = React.useMemo(() => ({
|
|
onPointerDown: handlePointerDown,
|
|
onPointerMove: handlePointerMove,
|
|
onPointerUp: handlePointerEnd,
|
|
onPointerCancel: handlePointerEnd,
|
|
}), [handlePointerDown, handlePointerEnd, handlePointerMove]);
|
|
|
|
return { asideRef, width, isResizing, handleProps };
|
|
}
|
|
|