diff --git a/frontend/src/lib/components/raw_apps/RawAppEditor.svelte b/frontend/src/lib/components/raw_apps/RawAppEditor.svelte index 8a689b0b62..95ae18f9f4 100644 --- a/frontend/src/lib/components/raw_apps/RawAppEditor.svelte +++ b/frontend/src/lib/components/raw_apps/RawAppEditor.svelte @@ -28,6 +28,7 @@ type RawAppRunSummary, type RawAppRunsProvider, type RawAppScreenshotRequester, + type LayoutFlag, RAW_APP_SANDBOX_FLAGS, RAW_APP_PREVIEW_RELAY, rawAppStorageKey, @@ -141,14 +142,14 @@ headBy?: string headAt?: string }) => void - /** Initial collapsed state for the file/runnable sidebar. The user's - * toggled preference is persisted under `sidebarStorageKey`; this prop - * only seeds the very first open. */ - defaultSidebarCollapsed?: boolean - /** localStorage key for the persisted sidebar state. Pass a different - * key when the editor is rendered in a context that wants its own - * preference. */ - sidebarStorageKey?: string + /** Collapsed state of the file/runnable sidebar, for a context that keeps its + * own preference; the editor follows it live when the caller swaps it and + * never collapses it on a narrow open. Defaults to the full-page editor's + * persisted preference. */ + sidebarCollapsedState?: LayoutFlag + /** "Split with Preview" state, likewise owned by the caller and followed live. + * Takes precedence over `defaultSplitWithPreview` and `compact`. */ + splitWithPreviewState?: LayoutFlag liveEditorDraftStoragePath?: string /** Indicator-only overrides forwarded to RawAppEditorHeader so the * sessions preview's AutosaveIndicator watches the session's @@ -239,8 +240,8 @@ diffDrawer = undefined, onNavigate, onDeploy = undefined, - defaultSidebarCollapsed = false, - sidebarStorageKey = 'raw-app-sidebar-collapsed', + sidebarCollapsedState = undefined, + splitWithPreviewState = undefined, liveEditorDraftStoragePath = undefined, autosaveWorkspace = undefined, autosavePath = undefined, @@ -592,7 +593,17 @@ addEventListener('message', function (e) { let activeTabId: string = $state(PREVIEW_TAB_ID) // Seed from the prop, then own the state locally so the user's toggle // after mount sticks even if the prop reference changes. - let splitWithPreview: boolean = $state(untrack(() => defaultSplitWithPreview && !compact)) + let ownSplitWithPreview: boolean = $state(untrack(() => defaultSplitWithPreview && !compact)) + const ownSplitState: LayoutFlag = { + get val() { + return ownSplitWithPreview + }, + set val(v) { + ownSplitWithPreview = v + } + } + const splitState = $derived(splitWithPreviewState ?? ownSplitState) + const splitWithPreview = $derived(splitState.val) const activeTabKind = $derived<'file' | 'runnable' | 'preview'>( activeTabId === PREVIEW_TAB_ID ? 'preview' @@ -819,21 +830,38 @@ addEventListener('message', function (e) { } function toggleSplit() { - if (splitWithPreview) { - splitWithPreview = false + splitState.val = !splitWithPreview + } + + // Entering split, whether toggled or by the caller swapping `splitWithPreviewState`: + // Preview leaves the left bar, so give the left pane the last file/runnable tab, + // or the default file when none is open (this also boots the UI Builder iframe). + // A swap to an unsplit state lands on Preview, the single-pane view's default; a + // manual unsplit keeps the tab the user is on. + let lastSplitState = untrack(() => splitState) + $effect(() => { + const state = splitState + const split = splitWithPreview + const swapped = state !== lastSplitState + lastSplitState = state + if (!split) { + if (swapped) untrack(() => select({ kind: 'preview' }, { force: true })) return } - // single → split: if Preview is active, move focus to the last - // file/runnable tab (it's leaving the left bar). - if (activeTabId === PREVIEW_TAB_ID) { + untrack(() => { + if (activeTabId !== PREVIEW_TAB_ID) return const lastUserTab = tabs .slice() .reverse() .find((t) => t.id !== PREVIEW_TAB_ID) - if (lastUserTab) activateTab(lastUserTab.id) - } - splitWithPreview = true - } + if (lastUserTab) { + activateTab(lastUserTab.id) + return + } + const def = pickDefaultFile(files) + if (def) select({ kind: 'file', path: def }) + }) + }) let yamlEditorDrawer: Drawer | undefined = $state(undefined) // Sidebar: honor the user's `%` but never shrink below SIDEBAR_PX_MIN. @@ -844,21 +872,15 @@ addEventListener('message', function (e) { const sidebarMinPercent = $derived(paneMinPercent(splitContainerWidth, SIDEBAR_PX_MIN)) const sidebarPanelSize = $derived(Math.max(rawSidebarSize, sidebarMinPercent)) - // Persisted across opens. Seeded with `defaultSidebarCollapsed` only when - // localStorage has no entry yet — callers (like the session preview pane) - // can default the initial state without overriding a user who has already - // expressed a preference. - const sidebarCollapsed = useLocalStorageValue( - sidebarStorageKey, - defaultSidebarCollapsed, - 'boolean' - ) + const ownSidebarCollapsed = useLocalStorageValue('raw-app-sidebar-collapsed', false, 'boolean') + const sidebarCollapsed = $derived(sidebarCollapsedState ?? ownSidebarCollapsed) - // Auto-compact when the editor opens in a narrow container (e.g. the session - // preview pane): drop to the merged single-pane view and retract the file - // sidebar. Applied once, on the first measured layout — later resizes are the - // user's call. The sidebar is set without persisting so a transient narrow - // open never overrides the user's saved expand/collapse preference. + // Auto-compact when the editor opens in a narrow container: drop to the merged + // single-pane view and retract the file sidebar. Applied once, on the first + // measured layout — later resizes are the user's call. The sidebar is set without + // persisting so a transient narrow open never overrides the saved preference. + // Caller-owned layout state is left alone: its owner already picks a default + // for the context it renders in. let rootWidth = $state(0) const NARROW_PX = 900 let appliedNarrowDefault = false @@ -867,8 +889,8 @@ addEventListener('message', function (e) { if (appliedNarrowDefault || w <= 0) return appliedNarrowDefault = true if (compact || w < NARROW_PX) { - splitWithPreview = false - sidebarCollapsed.setWithoutPersist(true) + if (!splitWithPreviewState) ownSplitWithPreview = false + if (!sidebarCollapsedState) ownSidebarCollapsed.setWithoutPersist(true) } }) @@ -2468,20 +2490,6 @@ addEventListener('message', function (e) { } }) - // Open a default file on mount (boots the iframe in split mode and gives - // the user something to edit on the left). When the caller seeded - // `defaultSplitWithPreview=false` we instead want the Preview tab as the - // only-visible / active surface, so skip the file-tab activation — the - // iframe still boots via `populateFiles`/`setFilesInIframe` even without - // a selected document. - onMount(() => { - if (!splitWithPreview) return - if (tabs.length === 1) { - const def = pickDefaultFile(files) - if (def) select({ kind: 'file', path: def }) - } - }) - // Drop tabs whose file/runnable no longer exists. Enumerate the keys: reading // only the `$state` proxy misses a `delete runnables[id]`, which is exactly // how a runnable disappears from the sidebar. diff --git a/frontend/src/lib/components/raw_apps/utils.ts b/frontend/src/lib/components/raw_apps/utils.ts index f0742adf03..107a255743 100644 --- a/frontend/src/lib/components/raw_apps/utils.ts +++ b/frontend/src/lib/components/raw_apps/utils.ts @@ -121,6 +121,10 @@ export function canonicalRawAppDiffValue(source: Record) { return stripRawAppDiffNoise(appSourceToDraftValue(source)) } +/** A boolean editor-layout preference (file sidebar, split with preview), owned and + * typically persisted by whoever passes it. */ +export type LayoutFlag = { val: boolean } + export type RawAppRuntimeLogLevel = 'log' | 'info' | 'warn' | 'error' | 'debug' export type RawAppRuntimeLogEntry = { level: RawAppRuntimeLogLevel diff --git a/frontend/src/lib/components/sessions/PreviewTabHost.svelte b/frontend/src/lib/components/sessions/PreviewTabHost.svelte index b6757762af..3e529851f6 100644 --- a/frontend/src/lib/components/sessions/PreviewTabHost.svelte +++ b/frontend/src/lib/components/sessions/PreviewTabHost.svelte @@ -379,6 +379,7 @@ {isActiveSession} {active} {newRawApp} + {fullscreen} /> {/await} {/if} diff --git a/frontend/src/lib/components/sessions/RawAppEditorView.svelte b/frontend/src/lib/components/sessions/RawAppEditorView.svelte index dc04e89fbe..9b90d48e6b 100644 --- a/frontend/src/lib/components/sessions/RawAppEditorView.svelte +++ b/frontend/src/lib/components/sessions/RawAppEditorView.svelte @@ -31,6 +31,7 @@ } from '$lib/components/raw_apps/utils' import type { RawAppDomRequester } from '$lib/components/raw_apps/rawAppDom' import type { InspectorElementInfo } from '$lib/components/copilot/chat/app/core' + import { useLocalStorageValue } from '$lib/svelte5Utils.svelte' let { runtime, @@ -39,7 +40,8 @@ onNavigate, isActiveSession = true, active = true, - newRawApp = false + newRawApp = false, + fullscreen = false }: { runtime: SessionRuntime path: string @@ -52,8 +54,34 @@ active?: boolean /** The tab was opened on an app the new-app builder just started. */ newRawApp?: boolean + /** Preview panel is in full screen. */ + fullscreen?: boolean } = $props() + // The side panel leaves little room for the file sidebar, full screen leaves plenty: + // each keeps its own sidebar and split preferences, the sidebar open by default only + // in full screen. + const panelSidebarCollapsed = useLocalStorageValue( + 'raw-app-sidebar-collapsed-preview', + true, + 'boolean' + ) + const fullscreenSidebarCollapsed = useLocalStorageValue( + 'raw-app-sidebar-collapsed-preview-fullscreen', + false, + 'boolean' + ) + const panelSplitWithPreview = useLocalStorageValue( + 'raw-app-split-with-preview-preview', + false, + 'boolean' + ) + const fullscreenSplitWithPreview = useLocalStorageValue( + 'raw-app-split-with-preview-preview-fullscreen', + false, + 'boolean' + ) + // This tab's own raw-app cell; each open app editor binds its own store. const cell = $derived(runtime.rawAppCell(path)) @@ -398,8 +426,8 @@ condensedHeader={true} onResetToDeployed={reloadDeployed} onDeploy={(e) => runtime.itemDeployed(workspaceId, 'raw_app', path, e.path)} - defaultSidebarCollapsed - sidebarStorageKey="raw-app-sidebar-collapsed-preview" + sidebarCollapsedState={fullscreen ? fullscreenSidebarCollapsed : panelSidebarCollapsed} + splitWithPreviewState={fullscreen ? fullscreenSplitWithPreview : panelSplitWithPreview} defaultSplitWithPreview={false} onRuntimeLogRequester={registerRuntimeLogRequester} onRunsProvider={registerRunsProvider}