feat: keep home's layout on both sides of the sidebar switch

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Guilhem Lemouel
2026-10-27 05:47:05 -07:00
co-authored by Claude Opus 5.5
parent 5ea8bd6e73
commit 589b982db9
17 changed files with 315 additions and 460 deletions
+62
View File
@@ -443,3 +443,65 @@ input[type='time']::-webkit-calendar-picker-indicator {
:root[data-home-sessions-transition='fade'] * {
view-transition-name: none !important;
}
/* Home's Workspace ⇄ AI Sessions switch (swapHomeSide in homeSessionsTransition.svelte.ts).
Home is the same page beside either list, so only the sidebar's list moves. The page shows
its new state at once, live, which lets the composer's own opening or folding play; named,
the composer would be held to the size it had when the switch began. The list's name exists
only while the switch runs: carried at all times, a send's move to the session page would
animate it too. */
:root[data-home-side-transition] .wm-vt-sidebar-list {
view-transition-name: home-sidebar-list;
}
:root[data-home-side-transition] [data-session-composer] {
view-transition-name: none !important;
}
:root[data-home-side-transition]::view-transition-old(root) {
display: none;
}
:root[data-home-side-transition]::view-transition-new(root) {
animation: none;
}
/* The list comes in from the side of the button pressed: AI Sessions is the right one. */
:root[data-home-side-transition]::view-transition-old(home-sidebar-list),
:root[data-home-side-transition]::view-transition-new(home-sidebar-list) {
animation-duration: 260ms;
animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
animation-fill-mode: both;
}
:root[data-home-side-transition='sessions']::view-transition-old(home-sidebar-list) {
animation-name: wm-side-out-left;
}
:root[data-home-side-transition='sessions']::view-transition-new(home-sidebar-list) {
animation-name: wm-side-in-right;
}
:root[data-home-side-transition='workspace']::view-transition-old(home-sidebar-list) {
animation-name: wm-side-out-right;
}
:root[data-home-side-transition='workspace']::view-transition-new(home-sidebar-list) {
animation-name: wm-side-in-left;
}
@keyframes wm-side-out-left {
to {
opacity: 0;
transform: translateX(-28px);
}
}
@keyframes wm-side-in-right {
from {
opacity: 0;
transform: translateX(28px);
}
}
@keyframes wm-side-out-right {
to {
opacity: 0;
transform: translateX(28px);
}
}
@keyframes wm-side-in-left {
from {
opacity: 0;
transform: translateX(-28px);
}
}
@@ -130,6 +130,10 @@
await aiChatDisplay?.attachContext(element)
}
export function foldComposer() {
aiChatDisplay?.foldComposer()
}
const historyManager = aiChatManager.historyManager
let aiChatDisplay: AIChatDisplay | undefined = $state(undefined)
@@ -314,6 +314,14 @@
aiChatInput?.focusInput(selection)
}
/** A starter composer back on one line, as a press outside it does: not while it holds a
* draft, which is never hidden. Takes the caret out, or the next keypress reopens it. */
export function foldComposer() {
closeComposer()
if (!composerOpened && composerEl?.contains(document.activeElement))
(document.activeElement as HTMLElement).blur()
}
/** Mention a workspace item in the draft, as "+" → Mention file does, and hand the user
* the caret after it. Focusing is what opens Home's one-line composer. */
export async function attachContext(element: ContextElement) {
@@ -1,7 +1,10 @@
// The layers the composer's controls open render in portals under <body>, outside the
// composer's own element: DropdownV2 menus, melt popovers, and the settings modals. Not
// `[data-menu]`: DropdownV2 puts it on its trigger too, and Home has triggers everywhere.
const OVERLAY = '[data-melt-dropdown-menu], [data-melt-popover-content], [role="dialog"]'
// `.wm-modal-form-popup` is Modal2's box, which carries no dialog role: without it a press
// inside Assistant settings folds the composer, and the modal goes with it.
const OVERLAY =
'[data-melt-dropdown-menu], [data-melt-popover-content], [role="dialog"], .wm-modal-form-popup'
/** Whether a pointer-down outside the composer still leaves it open: it landed in a menu or
* dialog, or one is open, and the press is closing it rather than leaving the composer. */
@@ -17,7 +17,6 @@
import { logFeatureUsage } from '$lib/utils/featureUsage'
import { hubBaseUrlStore, roleCapabilities, workspaceStore } from '$lib/stores'
import { homeDraft, sessionState } from '../sessions/sessionState.svelte'
import { homeListsSessions, homeSidebarList } from '../sessions/sidebarList.svelte'
import { currentWorkspaceRootId } from '../sessions/sessionScope.svelte'
import { HOME_SHOW_HUB } from '$lib/consts'
import { homeComposerPin, setHomeComposerRemoved } from './homeComposerPin.svelte'
@@ -93,10 +92,6 @@
)
let hero = $derived(showComposer && !removed)
// Beside the session list Home is the AI side's page: the composer rests open there. Beside
// the workspace nav it rests on one line.
const sessionsListed = $derived(homeListsSessions())
</script>
<div class="w-full {hero ? 'mt-2' : 'mb-1'}">
@@ -118,19 +113,14 @@
fork shares its parent's, and remounting for it only flashes the block. Also keyed
on the asks for another draft (New session, a draft picked in the session list). -->
{#if HomeSessionStarter && sessionState.hydrated}
<!-- Going into the composer is going to the AI side, so the sidebar lists sessions,
where the one sent from here opens. Nothing may focus the composer unasked (Home's
search holds the page's first focus), or every visit would flip the list. -->
<div class="contents" onfocusin={() => (homeSidebarList.val = 'sessions')}>
{#key `${$currentWorkspaceRootId}:${homeDraft.requests}`}
<HomeSessionStarter
{placeholder}
onSettled={(height) =>
rememberComposerHeight($workspaceStore ?? undefined, sessionsListed, height)}
restsOpen={sessionsListed}
/>
{/key}
</div>
<!-- Home is the same page beside either sidebar list. The switch only opens the
composer (AI Sessions) or folds it (Workspace); a focus moves nothing. -->
{#key `${$currentWorkspaceRootId}:${homeDraft.requests}`}
<HomeSessionStarter
{placeholder}
onSettled={(height) => rememberComposerHeight($workspaceStore ?? undefined, height)}
/>
{/key}
{:else}
{@render placeholder()}
{/if}
@@ -139,7 +129,7 @@
</div>
{#snippet placeholder()}
<HomeComposerSkeleton height={composerHeight($workspaceStore ?? undefined, sessionsListed)} />
<HomeComposerSkeleton height={composerHeight($workspaceStore ?? undefined)} />
{/snippet}
<HomeConnectDrawer bind:this={homeConnectDrawer} />
@@ -12,30 +12,14 @@
// the shortest open block: anything below it is one line, whatever the browser.
const OPEN_MIN_HEIGHT = OPEN_BOX_MIN + BLOCK_MARGINS
// The composer rests open beside the session list and on one line beside the workspace nav,
// so each side of the sidebar switch keeps its own height.
function heightSetting(workspace: string, sessionsListed: boolean): string {
return HEIGHT_SETTING + workspace + (sessionsListed ? ':sessions' : '')
}
/** The height Home's composer took when it last appeared in this workspace, beside this list. */
export function composerHeight(
workspace: string | undefined,
sessionsListed: boolean
): number | undefined {
const stored = workspace
? Number(getLocalSetting(heightSetting(workspace, sessionsListed)))
: NaN
/** The height Home's composer took when it last appeared in this workspace. */
export function composerHeight(workspace: string | undefined): number | undefined {
const stored = workspace ? Number(getLocalSetting(HEIGHT_SETTING + workspace)) : NaN
return Number.isFinite(stored) && stored > 0 ? stored : undefined
}
export function rememberComposerHeight(
workspace: string | undefined,
sessionsListed: boolean,
height: number
) {
if (workspace && height > 0)
storeLocalSetting(heightSetting(workspace, sessionsListed), String(height))
export function rememberComposerHeight(workspace: string | undefined, height: number) {
if (workspace && height > 0) storeLocalSetting(HEIGHT_SETTING + workspace, String(height))
}
</script>
@@ -1,179 +0,0 @@
<script module lang="ts">
import { preloadComponent } from '$lib/utils/preloadComponent.svelte'
// A tab renders a whole item through most of AIChat's code, monaco among it, which Home's
// static imports may not reach.
const previewTabHostComponent = preloadComponent(
() => import('$lib/components/sessions/PreviewTabHost.svelte')
)
</script>
<script lang="ts">
import { MonitorPlay, PanelRightClose, PanelRightOpen } from 'lucide-svelte'
import { SvelteSet } from 'svelte/reactivity'
import { goto } from '$lib/navigation'
import { Button } from '$lib/components/common'
import DraggableTabs, { type TabItem } from '$lib/components/common/tabs/DraggableTabs.svelte'
import PageHeaderContent from '$lib/components/PageHeaderContent.svelte'
import { useIsDarkMode } from '$lib/components/DarkModeObserver.svelte'
import { homeComposerContext } from '$lib/components/sessions/homeComposerContext.svelte'
import { onPreviewFrameMessage } from '$lib/components/sessions/previewFrameMessages'
import { previewLocationLabel } from '$lib/components/sessions/previewRouter'
import { withWorkspaceParam } from '$lib/components/sessions/sessionMode.svelte'
import {
sessionState,
type SessionPreviewTab
} from '$lib/components/sessions/sessionState.svelte'
import type { SessionPreviewTabs } from '$lib/components/sessions/sessionPreviewTabs.svelte'
import type { WorkspaceItem } from '$lib/components/workspacePicker'
import { workspaceStore } from '$lib/stores'
// Home's side of the session page's preview panel: the tabs of the draft in Home's composer,
// so a send hands them to the session page with the rest of the draft. Kept to tabs, close
// and collapse; the pickers and full screen are the session page's.
const runtime = $derived(homeComposerContext.runtime)
const owner: SessionPreviewTabs | undefined = $derived(runtime?.previewTabs)
const session = $derived(sessionState.sessions.find((s) => s.id === runtime?.sessionId))
const shown = $derived(!!owner && !owner.collapsed)
const isDarkMode = useIsDarkMode()
// The active tab's content is mounted, and so are the last few left through the strip: each
// is a whole Windmill page or editor.
const MAX_MOUNTED_TABS = 5
const shownTabIds = new SvelteSet<string>()
function noteShown(id: string) {
shownTabIds.delete(id)
shownTabIds.add(id)
while (shownTabIds.size > MAX_MOUNTED_TABS) {
const oldest = shownTabIds.values().next().value
if (oldest === undefined || oldest === id) break
shownTabIds.delete(oldest)
}
}
function label(tab: SessionPreviewTab): string {
return tab.friendlyLabel ?? previewLocationLabel(tab.loc || tab.url)
}
const tabItems = $derived<TabItem[]>(
(owner?.tabs ?? []).map((t) => ({ id: t.id, label: label(t), title: label(t) }))
)
function selectTab(id: string) {
if (owner?.activeId) noteShown(owner.activeId)
owner?.select(id)
}
function closeTab(id: string) {
owner?.close(id)
shownTabIds.delete(id)
}
function navigateEditorTo(item: WorkspaceItem) {
// A drag-and-drop app has no preview wrapper: it opens in its own editor.
if (item.kind === 'app' && !item.raw_app) {
void goto(withWorkspaceParam(`/apps/edit/${item.path}`, $workspaceStore ?? undefined))
return
}
owner?.navigate({ type: 'item', item })
}
function observeLocation(tab: SessionPreviewTab, frame: HTMLIFrameElement) {
try {
const win = frame.contentWindow
if (!win) return
const observe = () => {
try {
owner?.observeLocation(
tab.id,
win.location.pathname + win.location.search + win.location.hash
)
} catch {
// Mid-navigation the location can throw; the tab keeps its last one.
}
}
observe()
win.addEventListener('hashchange', observe)
win.addEventListener('popstate', observe)
} catch {
// Same as above.
}
}
</script>
<svelte:window onmessage={(e) => shown && onPreviewFrameMessage(e, owner)} />
{#if owner && !shown}
<PageHeaderContent actions={openButton} />
{/if}
{#snippet openButton()}
<Button
variant="subtle"
unifiedSize="sm"
startIcon={{ icon: PanelRightOpen }}
title="Open side panel"
onclick={() => owner?.setCollapsed(false)}
>
Open side panel
</Button>
{/snippet}
{#if owner && shown}
<div class="w-[45%] min-w-80 shrink-0 h-full p-2 pl-0 flex flex-col min-h-0">
<div
class="flex flex-col flex-1 min-h-0 overflow-hidden relative bg-surface rounded-md border border-light"
>
<div class="absolute top-1.5 left-1.5 z-30">
<Button
variant="subtle"
unifiedSize="xs"
iconOnly
startIcon={{ icon: PanelRightClose }}
title="Collapse preview"
aria-label="Collapse preview"
onclick={() => owner?.setCollapsed(true)}
/>
</div>
<DraggableTabs
tabs={tabItems}
activeId={owner.activeId}
onSelect={selectTab}
onClose={closeTab}
onReorder={(next) => owner?.reorder(next.map((t) => t.id))}
size="sm"
class="session-preview-tab-strip h-8 border-b border-light bg-surface-secondary/50 pl-9 pr-2"
/>
<div class="relative flex-1 min-h-0">
{#if previewTabHostComponent.current}
{@const TabHost = previewTabHostComponent.current}
{#each owner.tabs as tab (tab.id)}
{@const active = tab.id === owner.activeId}
<TabHost
{tab}
{session}
{runtime}
{active}
mounted={active || shownTabIds.has(tab.id)}
label={label(tab)}
darkMode={isDarkMode.val}
onNavigate={navigateEditorTo}
onSeeDetails={(item) => owner?.open({ type: 'item', item, mode: 'view' })}
onLoad={(frame) => observeLocation(tab, frame)}
/>
{/each}
{/if}
{#if owner.tabs.length === 0}
<div
class="absolute inset-0 flex flex-col items-center justify-center gap-2 text-center px-6 bg-surface"
>
<MonitorPlay size={28} class="text-tertiary" />
<span class="text-sm font-medium text-secondary">No preview open</span>
<span class="text-xs text-tertiary max-w-xs">
Click a script, flow or app on Home to preview it here.
</span>
</div>
{/if}
</div>
</div>
</div>
{/if}
@@ -40,7 +40,7 @@
import HomeSectionLabel from './HomeSectionLabel.svelte'
import HomeSectionCount from './HomeSectionCount.svelte'
import { QUICK_ACCESS_ROWS, homeQuickAccessSettings } from './homeQuickAccessSettings.svelte'
import { homeListsSessions } from '$lib/components/sessions/sidebarList.svelte'
import { sessionsSwitchShown } from '$lib/components/sessions/sidebarList.svelte'
import {
getEffectiveWorkspaceId,
homeDraft,
@@ -78,6 +78,24 @@
const RECENT_COUNT = 6
// The workspace's last sessions, one row of them: sent ones and drafts with text, not Home's
// own draft, which is the composer above. The session list holds the rest.
const CONTINUE_COUNT = 3
let continueSessions = $derived(
sessionsSwitchShown()
? sessionState.sessions
.filter(
(s) =>
!s.archived &&
s.id !== homeDraft.id &&
(!!s.workspace_id || !!s.draftPrompt?.trim()) &&
getEffectiveWorkspaceId(s) === workspace
)
.sort((a, b) => sessionLastActivityAt(b) - sessionLastActivityAt(a))
.slice(0, CONTINUE_COUNT)
: []
)
// The way back from Hide from Home is in the header menu HomeAIChat adds, which Home mounts
// only with the AI sessions beta on. Without it the section can't be hidden, and one hidden
// earlier shows again.
@@ -198,25 +216,6 @@
]
}
// Beside the session list the workspace's last sessions take the favorites' place: sent ones
// and drafts with text, not Home's own draft, which is the composer above.
const sessionsSide = $derived(homeListsSessions())
const showFavorites = $derived(homeQuickAccessSettings.showFavorites && !sessionsSide)
let recentSessions = $derived(
sessionsSide
? sessionState.sessions
.filter(
(s) =>
!s.archived &&
s.id !== homeDraft.id &&
(!!s.workspace_id || !!s.draftPrompt?.trim()) &&
getEffectiveWorkspaceId(s) === workspace
)
.sort((a, b) => sessionLastActivityAt(b) - sessionLastActivityAt(a))
.slice(0, RECENT_COUNT)
: []
)
// Assets are favorites too, but they open in the database manager rather than at a page,
// so they stay in the sidebar's menu.
let favorites: Entry[] = $derived(
@@ -227,7 +226,7 @@
// Favorites first, then what was opened lately; a starred item is listed once, as a favorite.
// With the favorites turned off, a starred item opened lately shows among the recent ones.
let recentAll: Entry[] = $derived.by(() => {
const { showRecent } = homeQuickAccessSettings
const { showFavorites, showRecent } = homeQuickAccessSettings
const starred = new Set(
showFavorites ? favorites.map((f) => `${asStarKind(f.kind)}/${f.path}`) : []
)
@@ -246,7 +245,7 @@
let recentLimit = $state(RECENT_COUNT)
let recentMore = $derived(Math.max(0, recentAll.length - recentLimit))
let entries: { item: Entry; favorite: boolean }[] = $derived([
...(showFavorites ? favorites : []).map((item) => ({
...(homeQuickAccessSettings.showFavorites ? favorites : []).map((item) => ({
item,
favorite: true
})),
@@ -257,10 +256,12 @@
// (the only way to turn the list back on) would leave with it.
let emptiedBySettings = $derived(
entries.length === 0 &&
recentSessions.length === 0 &&
((!showFavorites && favorites.length > 0) ||
((!homeQuickAccessSettings.showFavorites && favorites.length > 0) ||
(!homeQuickAccessSettings.showRecent && recentItems.list(workspace).length > 0))
)
let favoritesShown = $derived(
favoriteManager.loadedFor === workspace && (entries.length > 0 || emptiedBySettings) && !hidden
)
// Read when the pointer reaches the time, so the tooltip is current however long the
// page has been open.
@@ -281,7 +282,7 @@
}
// Everything the lists hold, the recent ones not loaded yet included.
let favoriteCount = $derived(showFavorites ? favorites.length : 0)
let favoriteCount = $derived(homeQuickAccessSettings.showFavorites ? favorites.length : 0)
let recentCount = $derived(recentAll.length)
// The cards fill one screen at a time, row by row, and the next screen scrolls in from the
@@ -289,7 +290,7 @@
// whole columns. The column counts follow the `auto-cols` breakpoints below.
let innerWidth = $state(1280)
let cols = $derived(innerWidth >= 1024 ? 3 : innerWidth >= 640 ? 2 : 1)
let cellCount = $derived(recentSessions.length + entries.length + (recentMore > 0 ? 1 : 0))
let cellCount = $derived(entries.length + (recentMore > 0 ? 1 : 0))
// Fewer rows when there aren't enough cards to fill a screen.
let rows = $derived(Math.min(homeQuickAccessSettings.rows, Math.ceil(cellCount / cols)))
@@ -431,19 +432,46 @@
</div>
{/snippet}
{#if continueSessions.length > 0}
<section class="flex flex-col gap-2 px-4 sm:px-0 pb-[30px]">
<HomeSectionLabel>Continue last session</HomeSectionLabel>
<div class="grid gap-2 grid-cols-1 sm:grid-cols-2 lg:grid-cols-3">
{#each continueSessions as session (session.id)}
<!-- Opened in place: an unsent draft goes to the composer above rather than bouncing
off the session page. A modified click opens the link as usual. -->
<a
href={sessionPageHref(session.id)}
class="w-full flex items-center gap-2 rounded-md border border-light bg-surface-tertiary hover:bg-surface-hover transition-colors min-w-0 px-2.5 py-2"
onclick={(e) => {
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return
e.preventDefault()
void openSession(session)
}}
>
<MessagesSquare size={14} class="shrink-0 text-ai" />
<span class="flex-1 text-2xs font-normal text-primary truncate"
>{session.summary ?? 'Untitled session'}</span
>
<span class="shrink-0 text-2xs text-secondary">
<TimeAgo
date={new Date(sessionLastActivityAt(session)).toISOString()}
compact
noSeconds
/>
</span>
</a>
{/each}
</div>
</section>
{/if}
<!-- Held back until the favorites are in: the recent cards are ready first, and the favorites
landing in front of them would push every card over. -->
{#if favoriteManager.loadedFor === workspace && (entries.length > 0 || recentSessions.length > 0 || emptiedBySettings) && !hidden}
{#if favoritesShown}
<!-- 30px under the cards: the gap from the composer down to this section's heading text. -->
<section class="flex flex-col gap-2 px-4 sm:px-0 pb-[30px]">
<div class="flex items-center gap-1 -my-1">
<HomeSectionLabel>
{#if recentSessions.length > 0}
Sessions <HomeSectionCount count={recentSessions.length} />
{/if}
{#if recentSessions.length > 0 && (favoriteCount > 0 || recentCount > 0)}
<span class="text-hint">·</span>
{/if}
{#if favoriteCount > 0}
Favorites <HomeSectionCount count={favoriteCount} />
{/if}
@@ -458,9 +486,9 @@
<DropdownV2 items={sectionMenu} size="xs" fixedHeight={false} />
</div>
</div>
{#if entries.length === 0 && recentSessions.length === 0}
{#if entries.length === 0}
<p class="text-2xs text-hint">
{showFavorites
{homeQuickAccessSettings.showFavorites
? 'No favorites yet. Star a script, flow or app to keep it here.'
: 'Nothing opened lately in this browser.'}
</p>
@@ -477,43 +505,15 @@
class="grid gap-2 overflow-x-auto no-scrollbar px-px -mx-px auto-cols-[85%] sm:auto-cols-[calc((100%_-_0.5rem)/2)] lg:auto-cols-[calc((100%_-_1rem)/3)]"
style:grid-template-rows="repeat({rows}, auto)"
>
{#each recentSessions as session, i (session.id)}
{@const at = cellPosition(i)}
<div class="min-w-0" style:grid-row={at.row} style:grid-column={at.column}>
<!-- Opened in place: an unsent draft goes to the composer above rather than
bouncing off the session page. A modified click opens the link as usual. -->
<a
href={sessionPageHref(session.id)}
class="w-full flex items-center gap-2 rounded-md border border-light bg-surface-tertiary hover:bg-surface-hover transition-colors min-w-0 px-2.5 py-2"
onclick={(e) => {
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return
e.preventDefault()
void openSession(session)
}}
>
<MessagesSquare size={14} class="shrink-0 text-ai" />
<span class="flex-1 text-2xs font-normal text-primary truncate"
>{session.summary ?? 'Untitled session'}</span
>
<span class="shrink-0 text-2xs text-secondary">
<TimeAgo
date={new Date(sessionLastActivityAt(session)).toISOString()}
compact
noSeconds
/>
</span>
</a>
</div>
{/each}
{#each entries as { item, favorite }, i (item.kind + '/' + item.path)}
{@const at = cellPosition(recentSessions.length + i)}
{@const at = cellPosition(i)}
<div class="min-w-0" style:grid-row={at.row} style:grid-column={at.column}>
{@render card(item, favorite)}
</div>
{/each}
{#if recentMore > 0}
{@const next = Math.min(recentMore, RECENT_COUNT)}
{@const at = cellPosition(recentSessions.length + entries.length)}
{@const at = cellPosition(entries.length)}
<div class="min-w-0" style:grid-row={at.row} style:grid-column={at.column}>
<Button
variant="subtle"
@@ -536,6 +536,8 @@
{/if}
</div>
</section>
{/if}
{#if favoritesShown || continueSessions.length > 0}
<HomeSectionLabel class="px-4 sm:px-0 pb-1">
Workspace items
{#if itemCount != undefined}
@@ -68,7 +68,6 @@
import BulkActionsBar from './BulkActionsBar.svelte'
import { HomeSelection, setHomeSelection, toBulkItem } from './homeSelection.svelte'
import HomeQuickAccess from './HomeQuickAccess.svelte'
import { homeListsSessions } from '../sessions/sidebarList.svelte'
const editRights = useEditRights()
@@ -2014,8 +2013,7 @@
<!-- Same gate the old create actions used: hidden from operators and in workspaces
whose direct-deploy protection cleared showEditButtons (NoDirectDeployAlert), since
the menu itself does no permission check. -->
<!-- Beside the session list items are made by asking the composer above. -->
{#if canCreateHere && !homeListsSessions()}
{#if canCreateHere}
<!-- No hub entry where the instance has the hub turned off: the same setting the
script and flow hub pickers observe. Nor for a builder: a hub project brings
scripts and apps along. -->
@@ -29,17 +29,14 @@
// Picked once; the parent remounts this on a workspace family switch and whenever
// another draft is asked for (New session, a draft picked in the session list).
// `placeholder` stands in while the chat waits on its config; `onSettled` reports the height
// the chat first took, for the next placeholder to take. `restsOpen` keeps the composer open
// at rest whatever the workspace holds; a workspace small enough that the composer is the
// page's main way in keeps it open anyway.
// the chat first took, for the next placeholder to take. A workspace small enough that the
// composer is the page's main way in keeps it open at rest.
let {
placeholder,
onSettled,
restsOpen = false
onSettled
}: {
placeholder?: Snippet
onSettled?: (height: number) => void
restsOpen?: boolean
} = $props()
const initialSession = homeStarterSession()
@@ -92,6 +89,7 @@
await aiChat?.attachContext(element)
},
focus: () => aiChat?.focusInput(),
fold: () => aiChat?.foldComposer(),
runtime
})
})
@@ -114,7 +112,7 @@
onAttachmentsChange={(a) => setSessionDraftAttachments(sessionId, a)}
starter={{
suggestions: starterPrompts.suggestions,
restsOpen: restsOpen || starterPrompts.fewItems
restsOpen: starterPrompts.fewItems
}}
viewTransitionNames
{onSent}
@@ -26,7 +26,13 @@ export function itemContextElement(item: {
return { type, path: item.path, title: item.path, summary: item.summary, deletable: true }
}
type Registration = { attach: Attach; focus: () => void; runtime: SessionRuntime }
type Registration = {
attach: Attach
focus: () => void
/** Back to one line, unless it holds a draft, and out of the caret's way. */
fold: () => void
runtime: SessionRuntime
}
// Raw: the runtime is shared with the session page and must stay the same object there.
let registered = $state.raw<Registration | undefined>(undefined)
@@ -51,6 +57,9 @@ export const homeComposerContext = {
focus(): void {
registered?.focus()
},
fold(): void {
registered?.fold()
},
/** Returns the unregister, which only clears its own registration: a remount registers
* the new composer before the old one is destroyed. */
register(registration: Registration): () => void {
@@ -1,4 +1,5 @@
import type { OnNavigate } from '@sveltejs/kit'
import { tick } from 'svelte'
// A send from Home keeps the composer in sight: the browser snapshots the page before and
// after the navigation to the session the send started, and glides the element that carries
@@ -50,3 +51,32 @@ export function homeSessionsTransition(navigation: OnNavigate): Promise<void> |
void transition.finished.then(done, done)
})
}
/** For the Workspace ⇄ AI Sessions switch on Home, which stays on the page: runs `swap` as a
* view transition in which the sidebar's list comes in from the side of the button pressed.
* The name and timing live in app.css, keyed on `data-home-side-transition`: set only for the
* switch, so a move to a session page does not pick the name up.
*
* Resolves once the swap is on the page and the click that asked for it has played out. */
export function swapHomeSide(to: 'workspace' | 'sessions', swap: () => void): Promise<void> {
if (
typeof document === 'undefined' ||
!document.startViewTransition ||
window.matchMedia('(prefers-reduced-motion: reduce)').matches
) {
swap()
return new Promise((resolve) => setTimeout(resolve, 0))
}
const root = document.documentElement
root.dataset.homeSideTransition = to
const transition = document.startViewTransition(async () => {
swap()
await tick()
})
const done = () => delete root.dataset.homeSideTransition
void transition.finished.then(done, done)
return transition.updateCallbackDone.then(
() => undefined,
() => undefined
)
}
@@ -1171,13 +1171,12 @@ function newTransientSession(): Session {
/** Whether a session opens in Home's composer rather than on a page of its own: unsent, not
* archived (its page holds the way back), and neither about an item (it carries preview tabs,
* which need the session page's panel), armed to send itself on arrival, nor already sending.
* Tabs opened from Home's own panel keep its draft there. */
* which need the session page's panel), armed to send itself on arrival, nor already sending. */
export function opensOnHome(s: Session): boolean {
return (
!s.workspace_id &&
!s.archived &&
(!s.previewTabs?.length || s.id === homeDraft.id) &&
!s.previewTabs?.length &&
!autoSendIsFresh(s) &&
!sendUnderWay(s.id)
)
@@ -27,6 +27,7 @@ import {
} from '../sidebar/workspaceSwitchUrl'
import { pinHomeComposer } from '../home/homeComposerPin.svelte'
import { homeComposerContext } from './homeComposerContext.svelte'
import { swapHomeSide } from './homeSessionsTransition.svelte'
// Type-only: erased at compile time, so the component graph stays out of this
// navigation seam (see the dynamic import in openEditorInSession).
import type { OpenInSessionSource } from './OpenInSessionButton.svelte'
@@ -64,13 +65,15 @@ export function noteArrival(url: URL): void {
if (homeSidebarList.val === 'workspace') rememberWorkspacePage(url.pathname + url.search)
}
/** The switch on Home, which belongs to both lists: it swaps the list and stays. */
/** The switch on Home, which belongs to both lists: it swaps the list and stays. Home is the
* same page beside either; the switch only opens its composer, for AI Sessions, or folds it.
* Both after the click has played out, or the switch button it landed on takes focus back. */
export function swapHomeList(list: SidebarList, homeHref: string): void {
homeSidebarList.val = list
if (list === 'workspace') rememberWorkspacePage(homeHref)
// The AI side of Home is its composer: going there puts the caret in it. After the click
// has played out, or the switch button it landed on takes focus back.
else setTimeout(() => homeComposerContext.focus(), 0)
const swapped = swapHomeSide(list, () => (homeSidebarList.val = list))
if (list === 'workspace') {
rememberWorkspacePage(homeHref)
void swapped.then(() => homeComposerContext.fold())
} else void swapped.then(() => homeComposerContext.focus())
}
// The session last opened, else the family's most recently used one. Scoped to the
@@ -31,8 +31,7 @@ export function sessionsSwitchShown(): boolean {
/** The list the sidebar shows while Home is open. Every other page decides its own (a
* session's page lists sessions, any other page the workspace nav) and, on arrival, sets
* this to it: Home sits above the switch and belongs to both, so it keeps the list you
* came from, until you go into its composer (HomeAIChat). Per browser, so a reload of Home
* keeps it too. */
* came from until the switch changes it. Per browser, so a reload of Home keeps it too. */
export const homeSidebarList = useLocalStorageValue<SidebarList>(
'windmill_sidebar_list',
'workspace',
@@ -45,13 +44,6 @@ export function sidebarListFor(pathname: string): SidebarList {
return pathname === '/' ? homeSidebarList.val : 'workspace'
}
/** Whether Home is laid out for sessions: the session list is beside it. Where the sidebar
* offers none, Home is the workspace's whatever list it kept, or its creation menu and
* favorites would be gone with no switch to bring them back. */
export function homeListsSessions(): boolean {
return homeSidebarList.val === 'sessions' && sessionsSwitchShown()
}
/** Turning AI Sessions back on asks to see them: Home, with the session list beside it. */
export function activateAiSessions(): void {
homeSidebarList.val = 'sessions'
@@ -324,8 +324,7 @@
// The /sessions page has its own gate for direct navigation.
const globalAiEnabled = isGlobalAiEnabled()
// A workspace that hid the assistant (`ai_config.copilot_disabled`) loses both entry
// points: the Workspace ⇄ AI Sessions switch and the legacy Ask-AI button. Home lays
// itself out by the same gate (`homeListsSessions`).
// points: the Workspace ⇄ AI Sessions switch and the legacy Ask-AI button.
const switchRowShown = $derived(sessionsSwitchShown())
// The page picks the list: a session's page lists sessions and a workspace page shows
// the workspace nav. Home keeps the list you came from. Where the switch is hidden, so
@@ -1280,7 +1279,7 @@ outside this layout, and their shortcut must reopen the URL that is their creden
{#if sidebarListsSessions}
<!-- The session list owns the column. A session's page shows workspace pages in
its preview side panel (the iframe renders its own nav). -->
<div class="px-2 py-2 flex flex-col gap-1 flex-1 min-h-0 overflow-y-auto">
<div class="wm-vt-sidebar-list px-2 py-2 flex flex-col gap-1 flex-1 min-h-0 overflow-y-auto">
<SessionPicker isCollapsed={collapsed} embedded collapsible={false} />
</div>
{@render settingsMenu(collapsed)}
@@ -1289,7 +1288,7 @@ outside this layout, and their shortcut must reopen the URL that is their creden
overflow fade hint. The three sections (Runs + Favorites + Search /
workspace items / instance settings) are spaced by the scroll area's
gap rather than each scrolling on its own. -->
<SidebarScrollArea color={darkMode ? SIDEBAR_BG_DARK : SIDEBAR_BG}>
<SidebarScrollArea class="wm-vt-sidebar-list" color={darkMode ? SIDEBAR_BG_DARK : SIDEBAR_BG}>
<!-- Section 1: Runs + Favorites + Search. -->
<div class="px-2 flex flex-col gap-1 pt-1">
{@render quickLinks(collapsed)}
+95 -142
View File
@@ -1,5 +1,5 @@
<script lang="ts">
import { AppService, FlowService, ScriptService, type OpenFlow, type Script } from '$lib/gen'
import { AppService, FlowService, type OpenFlow, type Script } from '$lib/gen'
import { roleCapabilities, userStore, workspaceStore } from '$lib/stores'
import { HOME_COLUMN_WIDTH } from '$lib/consts'
import { Alert, Button, Drawer, DrawerContent } from '$lib/components/common'
@@ -29,10 +29,6 @@
import { useSearchParams } from '$lib/svelte5UtilsKit.svelte'
import { z } from 'zod'
import HomeAIChat from '$lib/components/home/HomeAIChat.svelte'
import HomePreviewPanel from '$lib/components/home/HomePreviewPanel.svelte'
import { homeListsSessions } from '$lib/components/sessions/sidebarList.svelte'
import { homeComposerContext } from '$lib/components/sessions/homeComposerContext.svelte'
import { parsePreviewItemRoute } from '$lib/components/sessions/previewPaths'
import { isGlobalAiEnabled } from '$lib/components/copilot/chat/global/gate'
import { onMount, untrack } from 'svelte'
import OperatorTour from '$lib/components/tutorials/OperatorTour.svelte'
@@ -154,41 +150,6 @@
if (await hasSeenOperatorTour()) return
startTour()
})
// Beside the session list, a script, flow or app opens in the preview beside Home, as the
// draft's own tab, instead of taking Home's place. A modified click still opens it as a page,
// and a control inside the link (a row's star) acts on its own.
function openItemInPreview(e: MouseEvent) {
if (!homeListsSessions()) return
if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return
const owner = homeComposerContext.runtime?.previewTabs
const workspace = $workspaceStore
const target = e.target as Element | null
const link = target?.closest('a[href]')
const href = link?.getAttribute('href')
const route = href ? parsePreviewItemRoute(href) : null
if (!owner || !workspace || !link || !href || !route) return
const control = target?.closest('button, input, label, [role="button"]')
if (control && link.contains(control)) return
e.preventDefault()
e.stopPropagation()
const open = (path: string) =>
owner.open({
type: 'item',
item: { kind: route.kind, raw_app: route.raw_app, path, summary: '' },
mode: route.mode
})
// A deployed script's row links its hash, and a tab is keyed by the script's path. Every
// script path has a slash, so a segment without one is a hash.
if (route.kind === 'script' && !route.itemPath.includes('/')) {
ScriptService.getScriptByHash({ workspace, hash: route.itemPath }).then(
(script) => open(script.path),
() => goto(href)
)
return
}
open(route.itemPath)
}
</script>
<Drawer bind:this={codeViewer} size="900px">
@@ -329,119 +290,111 @@
<NoDirectDeployAlert onUpdateCanEditStatus={(v) => (showCreateButtons = v)} />
{/snippet}
<div class="flex flex-row w-full h-full min-h-0">
<div
bind:this={pageEl}
class="{fadeIn
? 'wm-page-in'
: ''} flex flex-col flex-1 min-w-0 h-full overflow-y-auto items-center"
style="scrollbar-gutter: stable both-edges;"
onclickcapture={openItemInPreview}
>
<!-- Where edits to this workspace are made is a fact about the workspace, so it sits in the
<div
bind:this={pageEl}
class="{fadeIn ? 'wm-page-in' : ''} flex flex-col w-full h-full overflow-y-auto items-center"
style="scrollbar-gutter: stable both-edges;"
>
<!-- Where edits to this workspace are made is a fact about the workspace, so it sits in the
header with the workspace's own name rather than above the list. -->
<PageHeaderContent actions={editRuleBadge} />
<PageHeaderContent actions={editRuleBadge} />
<ForkWorkspaceBanner />
<WorkspaceDraftsBanner />
<div class="{HOME_COLUMN_WIDTH} px-4 sm:px-8 md:px-8 h-fit w-full mb-6 shrink-0">
<!-- HomeAIChat carries both the AI composer and the AI-independent CLI/MCP connect row,
<ForkWorkspaceBanner />
<WorkspaceDraftsBanner />
<div class="{HOME_COLUMN_WIDTH} px-4 sm:px-8 md:px-8 h-fit w-full mb-6 shrink-0">
<!-- HomeAIChat carries both the AI composer and the AI-independent CLI/MCP connect row,
so it shows whenever the sessions beta is on; the composer itself is gated on the
workspace inside the component, which owns its own vertical spacing
because the hero and the bare connect row want different amounts of it. -->
{#if isGlobalAiEnabled()}
<HomeAIChat />
{/if}
{#if isGlobalAiEnabled()}
<HomeAIChat />
{/if}
{#if $workspaceStore == 'admins'}
<Alert title="Admins workspace">
The Admins workspace is for admins only and contains scripts whose purpose is to manage
your Windmill instance, such as keeping resource types up to date.
</Alert>
<div class="my-4"></div>
{/if}
{#if $workspaceStore == 'admins'}
<Alert title="Admins workspace">
The Admins workspace is for admins only and contains scripts whose purpose is to manage your
Windmill instance, such as keeping resource types up to date.
</Alert>
<div class="my-4"></div>
{/if}
{#if tab == 'hub'}
<div class="flex flex-col gap-y-16">
<div class="flex flex-col pb-8">
{#snippet toggleKinds()}
<ToggleButtonGroup
bind:selected={subtab}
onSelected={(v) => {
setQuery('kind', v, window.location.hash)
}}
noWFull
>
{#snippet children({ item })}
<ToggleButton value="script" label="Scripts" icon={Code} {item} />
<ToggleButton
value="flow"
label="Flows"
icon={FlowIcon}
selectedColor="#14b8a6"
{item}
/>
<ToggleButton
value="app"
label="Apps"
icon={LayoutDashboard}
selectedColor="#fb923c"
{item}
/>
{/snippet}
</ToggleButtonGroup>
<Button
startIcon={{ icon: ExternalLink }}
target="_blank"
href={$hubBaseUrlStore}
variant="default"
>
Hub
</Button>
{/snippet}
{#if tab == 'hub'}
<div class="flex flex-col gap-y-16">
<div class="flex flex-col pb-8">
{#snippet toggleKinds()}
<ToggleButtonGroup
bind:selected={subtab}
onSelected={(v) => {
setQuery('kind', v, window.location.hash)
}}
noWFull
>
{#snippet children({ item })}
<ToggleButton value="script" label="Scripts" icon={Code} {item} />
<ToggleButton
value="flow"
label="Flows"
icon={FlowIcon}
selectedColor="#14b8a6"
{item}
/>
<ToggleButton
value="app"
label="Apps"
icon={LayoutDashboard}
selectedColor="#fb923c"
{item}
/>
{/snippet}
</ToggleButtonGroup>
<Button
startIcon={{ icon: ExternalLink }}
target="_blank"
href={$hubBaseUrlStore}
variant="default"
>
Hub
</Button>
{/snippet}
{#if subtab == 'script'}
<PickHubScript
syncQuery
bind:filter={getFilter, setFilter}
on:pick={(e) => viewCode(e.detail)}
>
{#snippet children()}
{@render toggleKinds?.()}
{/snippet}
</PickHubScript>
{:else if subtab == 'flow'}
<PickHubFlow
syncQuery
bind:filter={getFilter, setFilter}
on:pick={(e) => viewFlow(e.detail)}
>
{#snippet children()}
{@render toggleKinds?.()}
{/snippet}
</PickHubFlow>
{:else if subtab == 'app'}
<PickHubApp
syncQuery
bind:filter={getFilter, setFilter}
on:pick={(e) => viewApp(e.detail)}
>
{#snippet children()}
{@render toggleKinds?.()}
{/snippet}
</PickHubApp>
{/if}
</div>
{#if subtab == 'script'}
<PickHubScript
syncQuery
bind:filter={getFilter, setFilter}
on:pick={(e) => viewCode(e.detail)}
>
{#snippet children()}
{@render toggleKinds?.()}
{/snippet}
</PickHubScript>
{:else if subtab == 'flow'}
<PickHubFlow
syncQuery
bind:filter={getFilter, setFilter}
on:pick={(e) => viewFlow(e.detail)}
>
{#snippet children()}
{@render toggleKinds?.()}
{/snippet}
</PickHubFlow>
{:else if subtab == 'app'}
<PickHubApp
syncQuery
bind:filter={getFilter, setFilter}
on:pick={(e) => viewApp(e.detail)}
>
{#snippet children()}
{@render toggleKinds?.()}
{/snippet}
</PickHubApp>
{/if}
</div>
{/if}
</div>
{#if tab == 'workspace'}
<ItemsList bind:subtab showEditButtons={showCreateButtons} />
</div>
{/if}
</div>
{#if homeListsSessions()}
<HomePreviewPanel />
{#if tab == 'workspace'}
<ItemsList bind:subtab showEditButtons={showCreateButtons} />
{/if}
</div>