mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-20 08:08:58 +00:00
fix: keep the AI sessions view mounted across navigation (#12479)
* fix: keep the AI sessions view mounted across navigation Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf: skip layout of the hidden sessions view off route Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: stop the page header flipping between two breadcrumb stages Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
This commit is contained in:
co-authored by
Claude Opus 5.5
Ruben Fiszel
parent
87c9d0d1fe
commit
7fa093f7d4
@@ -13,7 +13,7 @@
|
||||
import DropdownV2Inner from './DropdownV2Inner.svelte'
|
||||
import { pointerDownOutside } from '$lib/utils'
|
||||
import { createDropdownMenu, melt, createSync } from '@melt-ui/svelte'
|
||||
import { overlayPortalTarget } from '$lib/components/common/overlayHost.svelte'
|
||||
import { overlayPortalTarget, overlayShown } from '$lib/components/common/overlayHost.svelte'
|
||||
import type { MenubarMenuElements } from '@melt-ui/svelte'
|
||||
import ResolveOpen from '$lib/components/common/menu/ResolveOpen.svelte'
|
||||
import Button from '$lib/components/common/button/Button.svelte'
|
||||
@@ -89,6 +89,7 @@
|
||||
|
||||
// Overlays belong to the enclosing pane when there is one — see overlayHost.
|
||||
const hostPortal = overlayPortalTarget('body')
|
||||
const shown = overlayShown()
|
||||
|
||||
const {
|
||||
elements: { menu: menuEl, item, trigger },
|
||||
@@ -198,7 +199,7 @@
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
{#if open && !hidePopup}
|
||||
{#if open && !hidePopup && shown()}
|
||||
<div
|
||||
use:melt={$menuEl}
|
||||
data-menu
|
||||
|
||||
@@ -75,7 +75,8 @@ not this component) — so the lead can run the whole line.
|
||||
stage?: TrailStage
|
||||
/** Max widths the bar holds the names to, once dropping whole parts is not enough. */
|
||||
caps?: Partial<Record<Part, number>>
|
||||
/** The folders above the name truncate too: even the name at its last floor does not fit. */
|
||||
/** Even the name at its last floor does not fit: the folders above it truncate too, and a
|
||||
* section's own widget may shrink. */
|
||||
scopesGive?: boolean
|
||||
/** Filled in for the bar to choose a stage with; left undefined, nothing is measured. */
|
||||
measures?: TrailMeasures
|
||||
@@ -543,17 +544,21 @@ not this component) — so the lead can run the whole line.
|
||||
{#if section.content && measure}
|
||||
<span class="shrink-0" style="width: {sectionContentWidth}px"></span>
|
||||
{:else}
|
||||
<!-- A section's own widget lays out as a row: its title, and whatever belongs with it. -->
|
||||
<!-- A section's own widget lays out as a row: its title, and whatever belongs with it. It keeps
|
||||
its width, which the measured copies reserve, until even the last stage leaves it too
|
||||
little (`scopesGive`). Read while the row squeezes it, the width would let a wider stage
|
||||
fit, and the bar would flip between the two every frame. -->
|
||||
<span
|
||||
class={twMerge(
|
||||
SEGMENT,
|
||||
LAST,
|
||||
'hover:bg-transparent hover:text-emphasis',
|
||||
section.content ? '' : 'shrink-0'
|
||||
section.content && scopesGive ? '' : 'shrink-0'
|
||||
)}
|
||||
aria-current={measure ? undefined : 'page'}
|
||||
bind:clientWidth={
|
||||
() => sectionContentWidth, (w) => !measure && section.content && (sectionContentWidth = w)
|
||||
() => sectionContentWidth,
|
||||
(w) => !measure && section.content && !scopesGive && (sectionContentWidth = w)
|
||||
}
|
||||
>
|
||||
<!-- A plain label is the page's name, so it truncates the way an item's name does, in
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
Fills the layout's page header from the route that mounts it: the breadcrumb (an item's path, or a
|
||||
section name for a list) and the page's own buttons. Renders nothing itself.
|
||||
|
||||
Only a route page mounts this. An editor nested in a session pane or a drawer must not take over
|
||||
Only a route page mounts this, or the sessions view while its route is open: the layout keeps
|
||||
that view mounted on every page. An editor nested in a session pane or a drawer must not take over
|
||||
the header, so nesting is decided by the caller rather than guessed from context.
|
||||
-->
|
||||
<script lang="ts">
|
||||
|
||||
@@ -49,6 +49,8 @@
|
||||
</script>
|
||||
|
||||
<script>
|
||||
import { overlayShown } from '$lib/components/common/overlayHost.svelte'
|
||||
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property { HTMLElement|string} [target] - DOM Element or CSS Selector
|
||||
@@ -59,8 +61,12 @@
|
||||
|
||||
/** @type {Props} */
|
||||
let { target = 'body', name = undefined, class: clazz = undefined, children } = $props()
|
||||
|
||||
const shown = overlayShown()
|
||||
</script>
|
||||
|
||||
<div use:portal={{ target, name }} hidden class={clazz}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
{#if shown()}
|
||||
<div use:portal={{ target, name }} hidden class={clazz}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { classNames } from '$lib/utils'
|
||||
import ConditionalPortal from '$lib/components/common/drawer/ConditionalPortal.svelte'
|
||||
import { getOverlayHost, overlayHostActive } from '$lib/components/common/overlayHost.svelte'
|
||||
import {
|
||||
getOverlayHost,
|
||||
overlayHostActive,
|
||||
overlayShown
|
||||
} from '$lib/components/common/overlayHost.svelte'
|
||||
import { createEventDispatcher, type Snippet } from 'svelte'
|
||||
import { fade } from 'svelte/transition'
|
||||
import Button from '../button/Button.svelte'
|
||||
@@ -70,6 +74,7 @@
|
||||
const posClass = $derived(hostEl ? 'absolute' : 'fixed')
|
||||
|
||||
const hostActive = overlayHostActive()
|
||||
const shown = overlayShown()
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
@@ -163,7 +168,7 @@
|
||||
target={hostEl}
|
||||
class={hostEl ? 'contents' : undefined}
|
||||
>
|
||||
{#if open}
|
||||
{#if open && shown()}
|
||||
<div
|
||||
transition:fadeFast|local
|
||||
class={twMerge(posClass, 'top-0 bottom-0 left-0 right-0', zIndexClass)}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { createContextMenu, melt } from '@melt-ui/svelte'
|
||||
import { overlayPortalTarget } from '$lib/components/common/overlayHost.svelte'
|
||||
import { overlayPortalTarget, overlayShown } from '$lib/components/common/overlayHost.svelte'
|
||||
import { fly } from 'svelte/transition'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
import { untrack, type Snippet } from 'svelte'
|
||||
@@ -49,6 +49,7 @@
|
||||
|
||||
// Overlays belong to the enclosing pane when there is one — see overlayHost.
|
||||
const hostPortal = overlayPortalTarget('body')
|
||||
const shown = overlayShown()
|
||||
|
||||
const {
|
||||
elements: { menu: menuElement, item, trigger },
|
||||
@@ -111,7 +112,7 @@
|
||||
{@render children?.()}
|
||||
</div>
|
||||
|
||||
{#if $open}
|
||||
{#if $open && shown()}
|
||||
<div
|
||||
class="{getContextMenuContainerClass(zIndex)} {CONTEXT_MENU_ANIMATION_CLASSES}"
|
||||
use:melt={$menuElement}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
import {
|
||||
getOverlayHost,
|
||||
overlayHostActive,
|
||||
overlayShown,
|
||||
setTopmostSurface
|
||||
} from '$lib/components/common/overlayHost.svelte'
|
||||
|
||||
@@ -108,6 +109,9 @@
|
||||
const hostEl = $derived(overlayHost?.el())
|
||||
const posClass = $derived(hostEl ? 'absolute' : 'fixed')
|
||||
const hostActive = overlayHostActive()
|
||||
// The whole dialog, its place on the overlay stack included, goes while it is not drawn:
|
||||
// other pages read that stack to decide whether an Escape is theirs.
|
||||
const shown = overlayShown()
|
||||
|
||||
// A trail of one level is the dialog at its root, which the plain title already shows.
|
||||
const crumbs = $derived(trail && trail.length > 1 ? trail : undefined)
|
||||
@@ -186,175 +190,177 @@
|
||||
</h3>
|
||||
{/snippet}
|
||||
|
||||
<Disposable bind:open bind:this={disposable} preventEscape {minZIndex}>
|
||||
{#snippet children({ zIndex })}
|
||||
<!-- Always portalled, as Drawer is: rendered in place, any `transform`, `filter` or
|
||||
`overflow` on an ancestor confines the dialog and the nav rail paints over it. -->
|
||||
<ConditionalPortal condition target={hostEl} class={hostEl ? 'contents' : undefined}>
|
||||
{#if open}
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
||||
<div
|
||||
onclick={() => (open = false)}
|
||||
transition:fadeFast|local
|
||||
class="{posClass} top-0 bottom-0 left-0 right-0"
|
||||
style="z-index: {zIndex}"
|
||||
role="dialog"
|
||||
tabindex="-1"
|
||||
>
|
||||
{#if shown()}
|
||||
<Disposable bind:open bind:this={disposable} preventEscape {minZIndex}>
|
||||
{#snippet children({ zIndex })}
|
||||
<!-- Always portalled, as Drawer is: rendered in place, any `transform`, `filter` or
|
||||
`overflow` on an ancestor confines the dialog and the nav rail paints over it. -->
|
||||
<ConditionalPortal condition target={hostEl} class={hostEl ? 'contents' : undefined}>
|
||||
{#if open}
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
||||
<div
|
||||
class={twMerge(
|
||||
posClass,
|
||||
'inset-0 bg-gray-500 bg-opacity-75 transition-opacity',
|
||||
open ? 'ease-out duration-300 opacity-100' : 'ease-in duration-200 opacity-0'
|
||||
)}
|
||||
></div>
|
||||
|
||||
<div class="{posClass} inset-0 z-10 overflow-y-auto">
|
||||
onclick={() => (open = false)}
|
||||
transition:fadeFast|local
|
||||
class="{posClass} top-0 bottom-0 left-0 right-0"
|
||||
style="z-index: {zIndex}"
|
||||
role="dialog"
|
||||
tabindex="-1"
|
||||
>
|
||||
<div
|
||||
class="flex {fillHeight || fitHeight
|
||||
? 'h-full'
|
||||
: 'min-h-full'} items-center justify-center p-4"
|
||||
>
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
class={twMerge(
|
||||
posClass,
|
||||
'inset-0 bg-gray-500 bg-opacity-75 transition-opacity',
|
||||
open ? 'ease-out duration-300 opacity-100' : 'ease-in duration-200 opacity-0'
|
||||
)}
|
||||
></div>
|
||||
|
||||
<div class="{posClass} inset-0 z-10 overflow-y-auto">
|
||||
<div
|
||||
onclick={stopPropagation(bubble('click'))}
|
||||
class={twMerge(
|
||||
'relative transform overflow-hidden rounded-md bg-surface px-4 pt-5 pb-4 text-left shadow-xl transition-all sm:w-full sm:max-w-lg sm:p-6',
|
||||
// The margins are what keeps a content-sized dialog off the viewport edges; a
|
||||
// filling or fitting one takes its inset from the wrapper's padding instead.
|
||||
// Fitting is a grid, not a flex column: a grid row gives the body a definite
|
||||
// height while the dialog still hugs its content, so `h-full` resolves in it.
|
||||
// The column's 0 minimum is the grid's `min-w-0`: long unbreakable content
|
||||
// would otherwise widen it past the dialog.
|
||||
fillHeight
|
||||
? 'h-full flex flex-col'
|
||||
: fitHeight
|
||||
? kind == 'button'
|
||||
? 'max-h-full grid grid-cols-[minmax(0,1fr)] grid-rows-[minmax(0,1fr)_auto]'
|
||||
: 'max-h-full grid grid-cols-[minmax(0,1fr)] grid-rows-[minmax(0,1fr)]'
|
||||
: 'sm:my-8',
|
||||
c,
|
||||
open
|
||||
? 'ease-out duration-300 opacity-100 translate-y-0 sm:scale-100'
|
||||
: 'ease-in duration-200 opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95'
|
||||
)}
|
||||
{style}
|
||||
class="flex {fillHeight || fitHeight
|
||||
? 'h-full'
|
||||
: 'min-h-full'} items-center justify-center p-4"
|
||||
>
|
||||
{#if kind == 'X'}
|
||||
<div class="absolute top-4 right-4"
|
||||
><CloseButton on:close={() => (open = false)} /></div
|
||||
>
|
||||
{/if}
|
||||
<div class="flex {fillHeight ? 'flex-1 min-h-0' : fitHeight ? 'min-h-0' : ''}">
|
||||
<!-- min-w-0: without it this flex item takes its content's min-content width and
|
||||
stretches the modal past its max-width instead of letting content shrink. -->
|
||||
<div
|
||||
class="text-left flex-1 min-w-0 {fillHeight || fitHeight
|
||||
? 'flex flex-col min-h-0'
|
||||
: ''}"
|
||||
>
|
||||
<!-- pr-8 under `kind="X"`: the close button is absolutely positioned, so a long
|
||||
heading or the header actions would otherwise run under it. -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
onclick={stopPropagation(bubble('click'))}
|
||||
class={twMerge(
|
||||
'relative transform overflow-hidden rounded-md bg-surface px-4 pt-5 pb-4 text-left shadow-xl transition-all sm:w-full sm:max-w-lg sm:p-6',
|
||||
// The margins are what keeps a content-sized dialog off the viewport edges; a
|
||||
// filling or fitting one takes its inset from the wrapper's padding instead.
|
||||
// Fitting is a grid, not a flex column: a grid row gives the body a definite
|
||||
// height while the dialog still hugs its content, so `h-full` resolves in it.
|
||||
// The column's 0 minimum is the grid's `min-w-0`: long unbreakable content
|
||||
// would otherwise widen it past the dialog.
|
||||
fillHeight
|
||||
? 'h-full flex flex-col'
|
||||
: fitHeight
|
||||
? kind == 'button'
|
||||
? 'max-h-full grid grid-cols-[minmax(0,1fr)] grid-rows-[minmax(0,1fr)_auto]'
|
||||
: 'max-h-full grid grid-cols-[minmax(0,1fr)] grid-rows-[minmax(0,1fr)]'
|
||||
: 'sm:my-8',
|
||||
c,
|
||||
open
|
||||
? 'ease-out duration-300 opacity-100 translate-y-0 sm:scale-100'
|
||||
: 'ease-in duration-200 opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95'
|
||||
)}
|
||||
{style}
|
||||
>
|
||||
{#if kind == 'X'}
|
||||
<div class="absolute top-4 right-4"
|
||||
><CloseButton on:close={() => (open = false)} /></div
|
||||
>
|
||||
{/if}
|
||||
<div class="flex {fillHeight ? 'flex-1 min-h-0' : fitHeight ? 'min-h-0' : ''}">
|
||||
<!-- min-w-0: without it this flex item takes its content's min-content width and
|
||||
stretches the modal past its max-width instead of letting content shrink. -->
|
||||
<div
|
||||
class="flex flex-row items-start justify-between gap-2 min-w-0 {kind === 'X'
|
||||
? 'pr-8'
|
||||
class="text-left flex-1 min-w-0 {fillHeight || fitHeight
|
||||
? 'flex flex-col min-h-0'
|
||||
: ''}"
|
||||
>
|
||||
{#if crumbs && current}
|
||||
<div class="flex flex-row items-start gap-1 min-w-0">
|
||||
{#if back?.onclick}
|
||||
<!-- Pulled left so the heading lands about where the title sits at the
|
||||
root, and up so it reads against that heading rather than against
|
||||
the two lines together. -->
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="sm"
|
||||
iconOnly
|
||||
startIcon={{ icon: ChevronLeft }}
|
||||
title="Back to {back.label}"
|
||||
onClick={back.onclick}
|
||||
wrapperClasses="shrink-0 -ml-1 -mt-0.5"
|
||||
/>
|
||||
{/if}
|
||||
<div class="flex flex-col min-w-0">
|
||||
{@render heading(current.label, levelBadge, true)}
|
||||
<!-- The way back in full: the control above carries one level of it. -->
|
||||
<nav
|
||||
aria-label="Breadcrumb"
|
||||
class="flex flex-row items-center gap-0.5 min-w-0 text-xs text-secondary"
|
||||
>
|
||||
{#each crumbs.slice(0, -1) as segment, i (i)}
|
||||
{#if i > 0}
|
||||
<span class="flex shrink-0" in:fade={{ duration: 150 }}>
|
||||
<ChevronRight size={12} class="text-tertiary shrink-0" />
|
||||
</span>
|
||||
{/if}
|
||||
{#if segment.onclick}
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="2xs"
|
||||
onClick={segment.onclick}
|
||||
wrapperClasses="min-w-0 shrink"
|
||||
btnClasses="!px-0 !font-normal !text-xs text-secondary hover:text-emphasis hover:underline hover:!bg-transparent min-w-0"
|
||||
>
|
||||
<span class="truncate">{segment.label}</span>
|
||||
</Button>
|
||||
{:else}
|
||||
<span class="truncate" in:fade={{ duration: 150 }}
|
||||
>{segment.label}</span
|
||||
>
|
||||
{/if}
|
||||
{#if i === 0}
|
||||
{@render titleBadge?.()}
|
||||
{/if}
|
||||
{/each}
|
||||
</nav>
|
||||
<!-- pr-8 under `kind="X"`: the close button is absolutely positioned, so a long
|
||||
heading or the header actions would otherwise run under it. -->
|
||||
<div
|
||||
class="flex flex-row items-start justify-between gap-2 min-w-0 {kind === 'X'
|
||||
? 'pr-8'
|
||||
: ''}"
|
||||
>
|
||||
{#if crumbs && current}
|
||||
<div class="flex flex-row items-start gap-1 min-w-0">
|
||||
{#if back?.onclick}
|
||||
<!-- Pulled left so the heading lands about where the title sits at the
|
||||
root, and up so it reads against that heading rather than against
|
||||
the two lines together. -->
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="sm"
|
||||
iconOnly
|
||||
startIcon={{ icon: ChevronLeft }}
|
||||
title="Back to {back.label}"
|
||||
onClick={back.onclick}
|
||||
wrapperClasses="shrink-0 -ml-1 -mt-0.5"
|
||||
/>
|
||||
{/if}
|
||||
<div class="flex flex-col min-w-0">
|
||||
{@render heading(current.label, levelBadge, true)}
|
||||
<!-- The way back in full: the control above carries one level of it. -->
|
||||
<nav
|
||||
aria-label="Breadcrumb"
|
||||
class="flex flex-row items-center gap-0.5 min-w-0 text-xs text-secondary"
|
||||
>
|
||||
{#each crumbs.slice(0, -1) as segment, i (i)}
|
||||
{#if i > 0}
|
||||
<span class="flex shrink-0" in:fade={{ duration: 150 }}>
|
||||
<ChevronRight size={12} class="text-tertiary shrink-0" />
|
||||
</span>
|
||||
{/if}
|
||||
{#if segment.onclick}
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="2xs"
|
||||
onClick={segment.onclick}
|
||||
wrapperClasses="min-w-0 shrink"
|
||||
btnClasses="!px-0 !font-normal !text-xs text-secondary hover:text-emphasis hover:underline hover:!bg-transparent min-w-0"
|
||||
>
|
||||
<span class="truncate">{segment.label}</span>
|
||||
</Button>
|
||||
{:else}
|
||||
<span class="truncate" in:fade={{ duration: 150 }}
|
||||
>{segment.label}</span
|
||||
>
|
||||
{/if}
|
||||
{#if i === 0}
|
||||
{@render titleBadge?.()}
|
||||
{/if}
|
||||
{/each}
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
{@render heading(title, titleBadge, false)}
|
||||
{:else}
|
||||
{@render heading(title, titleBadge, false)}
|
||||
{/if}
|
||||
{@render settings?.()}
|
||||
</div>
|
||||
|
||||
{#if description}
|
||||
<p class="mt-1 text-xs text-secondary">{description}</p>
|
||||
{/if}
|
||||
{@render settings?.()}
|
||||
</div>
|
||||
|
||||
{#if description}
|
||||
<p class="mt-1 text-xs text-secondary">{description}</p>
|
||||
{/if}
|
||||
|
||||
<!-- `mt-1` when paginated: a page carries its own description as its first line,
|
||||
and it belongs where the dialog's own sat, right under the title. Fitting, the
|
||||
body is the scroller of last resort: 4px of padding, taken back by the margins,
|
||||
keeps the focus rings of controls along its edges from being clipped. -->
|
||||
<div
|
||||
class={fitHeight
|
||||
? 'mt-3 -mx-1 -mb-1 p-1 flex-1 min-h-0 overflow-y-auto text-sm text-primary'
|
||||
: `${paginated ? 'mt-1' : 'mt-4'} text-sm text-primary ${fillHeight ? 'flex-1 min-h-0' : ''}`}
|
||||
>
|
||||
{@render children_render?.()}
|
||||
<!-- `mt-1` when paginated: a page carries its own description as its first line,
|
||||
and it belongs where the dialog's own sat, right under the title. Fitting, the
|
||||
body is the scroller of last resort: 4px of padding, taken back by the margins,
|
||||
keeps the focus rings of controls along its edges from being clipped. -->
|
||||
<div
|
||||
class={fitHeight
|
||||
? 'mt-3 -mx-1 -mb-1 p-1 flex-1 min-h-0 overflow-y-auto text-sm text-primary'
|
||||
: `${paginated ? 'mt-1' : 'mt-4'} text-sm text-primary ${fillHeight ? 'flex-1 min-h-0' : ''}`}
|
||||
>
|
||||
{@render children_render?.()}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{#if kind == 'button'}
|
||||
<div class="flex items-center space-x-2 flex-row-reverse space-x-reverse mt-4">
|
||||
{@render actions?.()}
|
||||
<Button
|
||||
on:click={() => {
|
||||
dispatch('canceled')
|
||||
open = false
|
||||
}}
|
||||
color="light"
|
||||
size="sm"
|
||||
>
|
||||
{cancelText ?? 'Cancel'}
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{#if kind == 'button'}
|
||||
<div class="flex items-center space-x-2 flex-row-reverse space-x-reverse mt-4">
|
||||
{@render actions?.()}
|
||||
<Button
|
||||
on:click={() => {
|
||||
dispatch('canceled')
|
||||
open = false
|
||||
}}
|
||||
color="light"
|
||||
size="sm"
|
||||
>
|
||||
{cancelText ?? 'Cancel'}
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</ConditionalPortal>
|
||||
{/snippet}
|
||||
</Disposable>
|
||||
{/if}
|
||||
</ConditionalPortal>
|
||||
{/snippet}
|
||||
</Disposable>
|
||||
{/if}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import List from '$lib/components/common/layout/List.svelte'
|
||||
import { fade } from 'svelte/transition'
|
||||
import Disposable from '../drawer/Disposable.svelte'
|
||||
import { overlayHostActive, setTopmostSurface } from '../overlayHost.svelte'
|
||||
import { overlayHostActive, overlayShown, setTopmostSurface } from '../overlayHost.svelte'
|
||||
import { untrack } from 'svelte'
|
||||
|
||||
interface Props {
|
||||
@@ -94,6 +94,9 @@
|
||||
// at that drawer do not close the dialog underneath.
|
||||
let disposable: Disposable | undefined = $state(undefined)
|
||||
const hostActive = overlayHostActive()
|
||||
// The whole dialog, its place on the overlay stack included, goes while it is not drawn:
|
||||
// other pages read that stack to decide whether an Escape is theirs.
|
||||
const shown = overlayShown()
|
||||
setTopmostSurface(() => disposable?.isTopmost() ?? true)
|
||||
$effect(() => {
|
||||
isOpen
|
||||
@@ -135,80 +138,82 @@
|
||||
}}
|
||||
/>
|
||||
|
||||
<Disposable bind:open={isOpen} bind:this={disposable} preventEscape>
|
||||
{#snippet children({ zIndex })}
|
||||
{#if isOpen}
|
||||
<Portal name="always-mounted" {target}>
|
||||
<div
|
||||
class={'fixed top-0 bottom-0 left-0 right-0 transition-all overflow-auto bg-black bg-opacity-60 w-full h-full'}
|
||||
style="z-index: {zIndex}"
|
||||
transition:fadeFast|local
|
||||
>
|
||||
<div class="flex min-h-full items-center justify-center p-8">
|
||||
<div
|
||||
style={`width: ${widthMap[fixedWidth]}; ${
|
||||
heightMap[fixedHeight] ? `height: ${heightMap[fixedHeight]}; ` : ''
|
||||
}${css?.popup?.style || ''}`}
|
||||
class={twMerge(
|
||||
'max-h-screen-80 max-w-screen-80 rounded-lg relative bg-surface',
|
||||
formStyling ? 'py-4 px-6' : 'p-4',
|
||||
css?.popup?.class,
|
||||
'wm-modal-form-popup'
|
||||
)}
|
||||
use:clickOutside={{
|
||||
onClickOutside: () =>
|
||||
closeOnOutsideClick && !preventDismiss && topmostAtPress && close(),
|
||||
// A dropdown opened from inside the dialog portals its menu out of it, so a
|
||||
// click on one of its items lands outside this node and would close the
|
||||
// dialog under the menu.
|
||||
exclude: async () =>
|
||||
Array.from(document.querySelectorAll('[data-menu]')) as HTMLElement[]
|
||||
}}
|
||||
>
|
||||
<List gap="md">
|
||||
<div class="flex w-full">
|
||||
<List horizontal justify="between">
|
||||
<h3 class={formStyling ? 'font-semibold' : undefined}>{title}</h3>
|
||||
<div class="grow w-min-0">
|
||||
<List horizontal justify="between">
|
||||
<div class="min-w-0 grow">
|
||||
{@render headerLeft?.()}
|
||||
</div>
|
||||
<div class="min-w-0 grow-0 justify-end">
|
||||
<List horizontal justify="end">
|
||||
{@render headerRight?.()}
|
||||
<div class="w-8">
|
||||
<button
|
||||
id="modal-close-button"
|
||||
disabled={preventDismiss}
|
||||
onclick={() => {
|
||||
close()
|
||||
}}
|
||||
class="hover:bg-surface-hover rounded-full w-8 h-8 flex items-center justify-center transition-all disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent"
|
||||
>
|
||||
<X class="text-primary " />
|
||||
</button>
|
||||
</div>
|
||||
</List>
|
||||
</div>
|
||||
</List>
|
||||
</div>
|
||||
</List>
|
||||
</div>
|
||||
{#if shown()}
|
||||
<Disposable bind:open={isOpen} bind:this={disposable} preventEscape>
|
||||
{#snippet children({ zIndex })}
|
||||
{#if isOpen}
|
||||
<Portal name="always-mounted" {target}>
|
||||
<div
|
||||
class={'fixed top-0 bottom-0 left-0 right-0 transition-all overflow-auto bg-black bg-opacity-60 w-full h-full'}
|
||||
style="z-index: {zIndex}"
|
||||
transition:fadeFast|local
|
||||
>
|
||||
<div class="flex min-h-full items-center justify-center p-8">
|
||||
<div
|
||||
style={`width: ${widthMap[fixedWidth]}; ${
|
||||
heightMap[fixedHeight] ? `height: ${heightMap[fixedHeight]}; ` : ''
|
||||
}${css?.popup?.style || ''}`}
|
||||
class={twMerge(
|
||||
'max-h-screen-80 max-w-screen-80 rounded-lg relative bg-surface',
|
||||
formStyling ? 'py-4 px-6' : 'p-4',
|
||||
css?.popup?.class,
|
||||
'wm-modal-form-popup'
|
||||
)}
|
||||
use:clickOutside={{
|
||||
onClickOutside: () =>
|
||||
closeOnOutsideClick && !preventDismiss && topmostAtPress && close(),
|
||||
// A dropdown opened from inside the dialog portals its menu out of it, so a
|
||||
// click on one of its items lands outside this node and would close the
|
||||
// dialog under the menu.
|
||||
exclude: async () =>
|
||||
Array.from(document.querySelectorAll('[data-menu]')) as HTMLElement[]
|
||||
}}
|
||||
>
|
||||
<List gap="md">
|
||||
<div class="flex w-full">
|
||||
<List horizontal justify="between">
|
||||
<h3 class={formStyling ? 'font-semibold' : undefined}>{title}</h3>
|
||||
<div class="grow w-min-0">
|
||||
<List horizontal justify="between">
|
||||
<div class="min-w-0 grow">
|
||||
{@render headerLeft?.()}
|
||||
</div>
|
||||
<div class="min-w-0 grow-0 justify-end">
|
||||
<List horizontal justify="end">
|
||||
{@render headerRight?.()}
|
||||
<div class="w-8">
|
||||
<button
|
||||
id="modal-close-button"
|
||||
disabled={preventDismiss}
|
||||
onclick={() => {
|
||||
close()
|
||||
}}
|
||||
class="hover:bg-surface-hover rounded-full w-8 h-8 flex items-center justify-center transition-all disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent"
|
||||
>
|
||||
<X class="text-primary " />
|
||||
</button>
|
||||
</div>
|
||||
</List>
|
||||
</div>
|
||||
</List>
|
||||
</div>
|
||||
</List>
|
||||
</div>
|
||||
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="w-full flex grow min-h-0 {contentClasses}"
|
||||
onclick={stopPropagation(() => {})}
|
||||
>
|
||||
{@render body?.()}
|
||||
</div>
|
||||
</List>
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="w-full flex grow min-h-0 {contentClasses}"
|
||||
onclick={stopPropagation(() => {})}
|
||||
>
|
||||
{@render body?.()}
|
||||
</div>
|
||||
</List>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Portal>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</Disposable>
|
||||
</Portal>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</Disposable>
|
||||
{/if}
|
||||
|
||||
@@ -80,6 +80,21 @@ export function overlayHostActive(): () => boolean {
|
||||
return () => host?.active() ?? true
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this component's overlay is drawn. An overlay anchored to its host's element hides
|
||||
* with it; a host without one leaves its overlays on the viewport, where one left open while
|
||||
* the host is hidden would cover whatever the user went to. That overlay is not rendered
|
||||
* until the host is back, rather than hidden: an open drawer stays on its stack, an open
|
||||
* popover keeps its focus trap, and other pages stop handling keys while any
|
||||
* `[role="dialog"]` is in the document.
|
||||
*
|
||||
* Reads context, so call it during component initialisation.
|
||||
*/
|
||||
export function overlayShown(): () => boolean {
|
||||
const host = getOverlayHost()
|
||||
return () => !host || host.active() || !!host.el()
|
||||
}
|
||||
|
||||
const TOPMOST_SURFACE_KEY = 'topmostSurface'
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
import { SUPPORTED_CHAT_SCRIPT_LANGUAGES } from './script/core'
|
||||
import { copilotInfo } from '$lib/aiStore'
|
||||
import type { ComposerSelection } from './composerBox'
|
||||
import { overlayHostActive } from '$lib/components/common/overlayHost.svelte'
|
||||
|
||||
let {
|
||||
hideHeader = false,
|
||||
@@ -155,10 +156,15 @@
|
||||
$effect(() => {
|
||||
aiChatManager.updateMode(untrack(() => aiChatManager.mode))
|
||||
})
|
||||
|
||||
// A chat kept mounted while hidden (the sessions page's, on every other page) must leave
|
||||
// the browser its Cmd+L.
|
||||
const hostActive = overlayHostActive()
|
||||
</script>
|
||||
|
||||
<svelte:window
|
||||
onkeydown={(e) => {
|
||||
if (!hostActive()) return
|
||||
if ((e.ctrlKey || e.metaKey) && e.key === 'l') {
|
||||
e.preventDefault()
|
||||
aiChatDisplay?.focusInput()
|
||||
|
||||
@@ -48,6 +48,7 @@ callers that already know which section they mean, such as the "+" menu's Manage
|
||||
import { useOperatingWorkspace } from '$lib/components/operatingWorkspace.svelte'
|
||||
import AssistantDangerZoneSection from './AssistantDangerZoneSection.svelte'
|
||||
import { useActingUser } from '$lib/actingUser.svelte'
|
||||
import { overlayHostActive } from '$lib/components/common/overlayHost.svelte'
|
||||
|
||||
// Prefilled title marks the issue as AI Sessions feedback for triage.
|
||||
const FEEDBACK_ISSUE_URL =
|
||||
@@ -64,6 +65,7 @@ callers that already know which section they mean, such as the "+" menu's Manage
|
||||
const operatingWorkspace = useOperatingWorkspace()
|
||||
|
||||
const aiChatManager = getAiChatManager()
|
||||
const hostActive = overlayHostActive()
|
||||
|
||||
let isOpen = $state(false)
|
||||
let section = $state<AssistantSettingsSection>('tools')
|
||||
@@ -109,7 +111,8 @@ callers that already know which section they mean, such as the "+" menu's Manage
|
||||
* it would then answer the key it was revealed by — reverting the very draft the
|
||||
* user was brought here to see. */
|
||||
function onKeydown(event: KeyboardEvent) {
|
||||
if (!isOpen || event.key !== 'Escape') return
|
||||
// Hidden hosts stay mounted and still receive window keys — see overlayHost.
|
||||
if (!isOpen || event.key !== 'Escape' || !hostActive()) return
|
||||
const blocker = blockingSection
|
||||
if (!blocker || blocker === section) return
|
||||
event.preventDefault()
|
||||
@@ -132,7 +135,9 @@ callers that already know which section they mean, such as the "+" menu's Manage
|
||||
// assistant can call here, so it must not shift when the autonomy picker does.
|
||||
// The danger zone writes the workspace's AI config, which only its admins may change.
|
||||
const acting = useActingUser(() => ws)
|
||||
let isWsAdmin = $derived(!!acting.current && (acting.current.is_admin || acting.current.is_super_admin))
|
||||
let isWsAdmin = $derived(
|
||||
!!acting.current && (acting.current.is_admin || acting.current.is_super_admin)
|
||||
)
|
||||
|
||||
let tools = $derived(summarizeTools(aiChatManager.availableTools))
|
||||
let providerTools = $derived(aiChatManager.providerTools)
|
||||
@@ -326,9 +331,7 @@ callers that already know which section they mean, such as the "+" menu's Manage
|
||||
<AssistantPermissionsSection {ws} />
|
||||
</div>
|
||||
{#if isWsAdmin}
|
||||
<div
|
||||
class="{section === 'danger' ? 'block' : 'hidden'} grow min-h-0 overflow-y-auto pr-2"
|
||||
>
|
||||
<div class="{section === 'danger' ? 'block' : 'hidden'} grow min-h-0 overflow-y-auto pr-2">
|
||||
<AssistantDangerZoneSection {ws} />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { untrack } from 'svelte'
|
||||
import { overlayPortalTarget } from '$lib/components/common/overlayHost.svelte'
|
||||
import { overlayPortalTarget, overlayShown } from '$lib/components/common/overlayHost.svelte'
|
||||
import { createBubbler } from 'svelte/legacy'
|
||||
|
||||
const bubble = createBubbler()
|
||||
@@ -82,6 +82,7 @@
|
||||
|
||||
// Overlays belong to the enclosing pane when there is one — see overlayHost.
|
||||
const hostPortal = overlayPortalTarget('body')
|
||||
const shown = overlayShown()
|
||||
|
||||
// Use the passed createMenu function
|
||||
const menu = untrack(() => createMenu)({
|
||||
@@ -232,7 +233,7 @@
|
||||
</button>
|
||||
|
||||
<!--svelte-ignore a11y_no_static_element_interactions-->
|
||||
{#if open || renderContent}
|
||||
{#if (open || renderContent) && shown()}
|
||||
<div
|
||||
use:melt={$menuElement}
|
||||
data-menu
|
||||
|
||||
@@ -17,7 +17,12 @@
|
||||
import { debounce, pointerDownOutside } from '$lib/utils'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
import { createEventDispatcher, untrack } from 'svelte'
|
||||
import { getOverlayHost, overlayPortalTarget } from '$lib/components/common/overlayHost.svelte'
|
||||
import {
|
||||
getOverlayHost,
|
||||
overlayHostActive,
|
||||
overlayPortalTarget,
|
||||
overlayShown
|
||||
} from '$lib/components/common/overlayHost.svelte'
|
||||
import { Button } from '$lib/components/common'
|
||||
import DocLink from '$lib/components/apps/editor/settingsPanel/DocLink.svelte'
|
||||
import type { FloatingConfig } from '@melt-ui/svelte/internal/actions/floating'
|
||||
@@ -119,6 +124,8 @@
|
||||
// drawer), else the document.
|
||||
const overlayHost = getOverlayHost()
|
||||
const hostPortal = overlayPortalTarget('body')
|
||||
const shown = overlayShown()
|
||||
const hostActive = overlayHostActive()
|
||||
const fullScreenHost = $derived(fullScreen ? overlayHost?.el() : undefined)
|
||||
// `null` is melt's "render in place" and must survive; only an absent prop defers to the host.
|
||||
let dynamicPortal = $derived(
|
||||
@@ -233,7 +240,7 @@
|
||||
})
|
||||
</script>
|
||||
|
||||
<svelte:window onkeydown={(e) => isOpen && onKeyDown(e)} />
|
||||
<svelte:window onkeydown={(e) => isOpen && hostActive() && onKeyDown(e)} />
|
||||
|
||||
<button
|
||||
class={className}
|
||||
@@ -266,12 +273,12 @@
|
||||
{@render trigger?.({ isOpen })}
|
||||
</button>
|
||||
|
||||
{#if fullScreen && isOpen && !disablePopup}
|
||||
{#if fullScreen && isOpen && !disablePopup && shown()}
|
||||
<div use:melt={$overlay} class="{fullScreenHost ? 'absolute' : 'fixed'} inset-0 z-10 bg-black/50"
|
||||
></div>
|
||||
{/if}
|
||||
|
||||
{#if isOpen && !disablePopup}
|
||||
{#if isOpen && !disablePopup && shown()}
|
||||
<div
|
||||
onmouseenter={() => {
|
||||
if (openOnHover) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { zIndexes } from '$lib/zIndexes'
|
||||
|
||||
import { createTooltip, melt } from '@melt-ui/svelte'
|
||||
import { overlayPortalTarget } from '$lib/components/common/overlayHost.svelte'
|
||||
import { overlayPortalTarget, overlayShown } from '$lib/components/common/overlayHost.svelte'
|
||||
import { fade } from 'svelte/transition'
|
||||
import TooltipInner from '../TooltipInner.svelte'
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
// `null` is melt's "render in place" and must survive; only an absent prop defers to the host.
|
||||
const hostPortal = overlayPortalTarget('body')
|
||||
const effectivePortal = () => (portal === undefined ? hostPortal() : portal)
|
||||
const shown = overlayShown()
|
||||
|
||||
const {
|
||||
elements: { trigger, content },
|
||||
@@ -130,7 +131,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if $open && !disablePopup}
|
||||
{#if $open && !disablePopup && shown()}
|
||||
<div use:melt={$content} transition:fade={{ duration: 100 }} style="z-index: {zIndexes.tooltip}">
|
||||
<TooltipInner {documentationLink} {customBgClass}>
|
||||
{#snippet children()}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import { PlusIcon } from 'lucide-svelte'
|
||||
import GenericDropdown from './GenericDropdown.svelte'
|
||||
import { Debounced } from 'runed'
|
||||
import { overlayHostActive } from '$lib/components/common/overlayHost.svelte'
|
||||
|
||||
let {
|
||||
processedItems: _processedItems,
|
||||
@@ -74,11 +75,14 @@
|
||||
// Dirty fix to prevent a rendering bug where the ul is present in the layout but
|
||||
// displays as empty. It only happens with overflow-y-auto set.
|
||||
let enableOverflowYAuto = new Debounced(() => isVisible, 15)
|
||||
|
||||
// Hidden hosts stay mounted and still receive window keys — see overlayHost.
|
||||
const hostActive = overlayHostActive()
|
||||
</script>
|
||||
|
||||
<svelte:window
|
||||
onkeydown={(e) => {
|
||||
if (!isVisible || !processedItems?.length) return
|
||||
if (!isVisible || !processedItems?.length || !hostActive()) return
|
||||
if (e.key === 'ArrowUp' && keyArrowPos !== undefined && processedItems.length > 0) {
|
||||
keyArrowPos = keyArrowPos <= 0 ? undefined : keyArrowPos - 1
|
||||
} else if (e.key === 'ArrowDown') {
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
} from '$lib/stores'
|
||||
import { canCreateFork } from '$lib/utils/editInFork'
|
||||
import { isCloudHosted } from '$lib/cloud'
|
||||
import { sessionState, type Session } from './sessionState.svelte'
|
||||
import { untrack } from 'svelte'
|
||||
import type { Session } from './sessionState.svelte'
|
||||
import { getRuntime } from './sessionRuntime.svelte'
|
||||
import { useSessionPermissions } from './sessionPermissions.svelte'
|
||||
import SessionDiffDrawer from './SessionDiffDrawer.svelte'
|
||||
@@ -51,12 +52,15 @@
|
||||
// session diff drawer.
|
||||
let {
|
||||
session,
|
||||
onScreen,
|
||||
onMove,
|
||||
onCreateForkAndMove,
|
||||
onArchive,
|
||||
onDelete
|
||||
}: {
|
||||
session: Session
|
||||
/** Whether this is the session the sessions page shows, with its route open. */
|
||||
onScreen: boolean
|
||||
onMove?: (workspaceId: string) => void
|
||||
onCreateForkAndMove?: (fork: {
|
||||
parent_workspace_id: string
|
||||
@@ -135,22 +139,26 @@
|
||||
})
|
||||
|
||||
// Refresh when the user comes back to this view — covers edits made
|
||||
// elsewhere while we were away. Two signals: visibilitychange (another tab
|
||||
// in the same window) and window focus (a second browser window, where this
|
||||
// elsewhere while we were away. Three signals: coming back on screen from
|
||||
// another session or page (the bar stays mounted meanwhile, so nothing else
|
||||
// refetches; the first time, mounting did), visibilitychange (another tab in
|
||||
// the same window) and window focus (a second browser window, where this
|
||||
// tab never goes hidden so visibilitychange never fires — e.g. deploying
|
||||
// from the full-page editor side by side).
|
||||
let shownBefore = false
|
||||
$effect(() => {
|
||||
if (!committedId) return
|
||||
function refreshIfCurrent() {
|
||||
if (!committedId || !onScreen) return
|
||||
if (shownBefore) untrack(refreshDock)
|
||||
shownBefore = true
|
||||
function refreshIfVisible() {
|
||||
if (document.visibilityState !== 'visible') return
|
||||
if (sessionState.currentSessionId !== session.id) return
|
||||
refreshDock()
|
||||
}
|
||||
document.addEventListener('visibilitychange', refreshIfCurrent)
|
||||
window.addEventListener('focus', refreshIfCurrent)
|
||||
document.addEventListener('visibilitychange', refreshIfVisible)
|
||||
window.addEventListener('focus', refreshIfVisible)
|
||||
return () => {
|
||||
document.removeEventListener('visibilitychange', refreshIfCurrent)
|
||||
window.removeEventListener('focus', refreshIfCurrent)
|
||||
document.removeEventListener('visibilitychange', refreshIfVisible)
|
||||
window.removeEventListener('focus', refreshIfVisible)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -68,25 +68,33 @@
|
||||
import { fixupUrlAfterWorkspaceSwitch } from '$lib/components/sidebar/workspaceSwitchUrl'
|
||||
import { getOrCreateRuntime, removeSession } from './sessionRuntime.svelte'
|
||||
import { splitterPointerCapture } from '$lib/utils/splitterPointerCapture'
|
||||
import { overlayStack, setOverlayHost } from '$lib/components/common/overlayHost.svelte'
|
||||
import { AIWorkMode } from '$lib/components/copilot/chat/workMode'
|
||||
import { resolvePreviewTab } from './previewRouter'
|
||||
import { whereIs } from './sessionPreviewTabs.svelte'
|
||||
|
||||
let {
|
||||
sessionId,
|
||||
headerInPage = false,
|
||||
onScreen = false,
|
||||
covered = false,
|
||||
previewTabName
|
||||
}: {
|
||||
sessionId: string
|
||||
/** True for the session the page is showing: its header rides the page header bar. */
|
||||
headerInPage?: boolean
|
||||
/** True for the session the sessions page is showing, with its route open: its header
|
||||
* rides the page header bar, and only it may send, take focus or load the copilot
|
||||
* config. The page stays mounted, hidden, while the user is on other pages. */
|
||||
onScreen?: boolean
|
||||
/** True while the page holds this wrapper inert under an overlay, where nothing takes focus. */
|
||||
covered?: boolean
|
||||
/** The name the preview's tab strip shows for a tab, without its side marker. */
|
||||
previewTabName: (tab: SessionPreviewTab) => string
|
||||
} = $props()
|
||||
|
||||
// The overlays stay on the viewport and its stack. While this column is off screen they are
|
||||
// not drawn and their window keys go quiet: a dialog left open would otherwise cover the
|
||||
// page the user went to, and its Enter would confirm it there.
|
||||
setOverlayHost({ el: () => undefined, drawers: overlayStack(), active: () => onScreen })
|
||||
|
||||
// Parent keys by sessionId; this wrapper only mounts when the session exists.
|
||||
// Captured at script-init so we can synchronously bind context.
|
||||
const initialSession = sessionState.sessions.find((s) => s.id === sessionId)
|
||||
@@ -137,7 +145,7 @@
|
||||
// an intent this wrapper will not claim — stale, or armed on a session the
|
||||
// page is only keeping warm in the background — still gets a composer, whose
|
||||
// mount-time empty draft would otherwise erase the prompt from the record.
|
||||
const armedAtInit = sessionState.currentSessionId === sessionId && peekSessionAutoSend(sessionId)
|
||||
const armedAtInit = untrack(() => onScreen) && peekSessionAutoSend(sessionId)
|
||||
|
||||
// The composer's text before AIChat mounts, typed into the placeholder, and then the real
|
||||
// composer's initial draft.
|
||||
@@ -171,7 +179,7 @@
|
||||
// and the prompt to never be sent. Claimed only for the session the user
|
||||
// landed on; a background wrapper would fire the turn off-screen.
|
||||
$effect(() => {
|
||||
if (sessionState.currentSessionId !== sessionId) return
|
||||
if (!onScreen) return
|
||||
if (!session?.autoSendDraftAt || !runtime) return
|
||||
untrack(() => {
|
||||
const prompt = getSessionDraftPrompt(sessionId)
|
||||
@@ -194,11 +202,12 @@
|
||||
// on, not the navigation workspace — a session deliberately leaves
|
||||
// $workspaceStore on the nav workspace, so keying off it would pick the model
|
||||
// and provider from the wrong workspace's AI config for a fork-scoped session.
|
||||
// Only the active session may write this: copilotInfo/copilotSessionModel are
|
||||
// Only the session on screen may write this: copilotInfo/copilotSessionModel are
|
||||
// global, and warm background wrappers (each in their own workspace) would
|
||||
// otherwise race to clobber the active chat's model config.
|
||||
// otherwise race to clobber the active chat's model config. Off the route the
|
||||
// layout loads the navigation workspace's, so coming back loads this one again.
|
||||
$effect(() => {
|
||||
if (sessionState.currentSessionId !== sessionId) return
|
||||
if (!onScreen) return
|
||||
const ws = actingWorkspaceId ?? $workspaceStore
|
||||
if (ws) {
|
||||
loadCopilot(ws)
|
||||
@@ -306,8 +315,9 @@
|
||||
// loading.
|
||||
let aiChat: AIChat | undefined = $state(undefined)
|
||||
$effect(() => {
|
||||
if (sessionState.currentSessionId !== sessionId) {
|
||||
// The user left for another session: coming back is an activation, which focuses.
|
||||
if (!onScreen) {
|
||||
// The user left for another session or page: coming back is an activation, which
|
||||
// focuses.
|
||||
handoff = undefined
|
||||
return
|
||||
}
|
||||
@@ -328,8 +338,7 @@
|
||||
chatShown ||=
|
||||
!!aiChatComponent.current &&
|
||||
!placeholderComposing &&
|
||||
(sessionState.currentSessionId !== sessionId ||
|
||||
$copilotWorkspace === (actingWorkspaceId ?? $workspaceStore))
|
||||
(!onScreen || $copilotWorkspace === (actingWorkspaceId ?? $workspaceStore))
|
||||
return chatShown
|
||||
})
|
||||
|
||||
@@ -655,6 +664,7 @@
|
||||
{/if}
|
||||
<SessionChangesBar
|
||||
{session}
|
||||
{onScreen}
|
||||
onMove={(workspaceId) => moveAndActivate(workspaceId)}
|
||||
onCreateForkAndMove={(fork) => createForkAndMove(fork)}
|
||||
onArchive={() => archiveAndReset()}
|
||||
@@ -761,7 +771,7 @@
|
||||
/>
|
||||
{/snippet}
|
||||
|
||||
{#if headerInPage}
|
||||
{#if onScreen}
|
||||
<!-- The chat's own header row is the page header on this route: the session's name is its
|
||||
breadcrumb, and the menu is its action. The workspace it acts on is named by the
|
||||
breadcrumb's own workspace part, the way every other route names it — a session in a
|
||||
@@ -825,7 +835,7 @@
|
||||
? 'Ask followup'
|
||||
: (previewedItemPlaceholder ?? composerPlaceholder)}
|
||||
disabled={isUnavailable || !!session.archived}
|
||||
autofocus={sessionState.currentSessionId === sessionId && !covered}
|
||||
autofocus={onScreen && !covered}
|
||||
onSelectionChange={(selection) => (handoff = selection ?? null)}
|
||||
onCompositionChange={(composing) => (placeholderComposing = composing)}
|
||||
/>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,6 +18,7 @@
|
||||
workspaceSubtreeRows
|
||||
} from '$lib/utils/workspaceHierarchy'
|
||||
import { useForkableWorkspaces } from '$lib/utils/useForkableWorkspaces.svelte'
|
||||
import { overlayHostActive } from '$lib/components/common/overlayHost.svelte'
|
||||
import { isNewTabClick } from '$lib/navigation'
|
||||
import { canCreateFork } from '$lib/utils/editInFork'
|
||||
import { canFork, capabilitiesIn } from '$lib/roleCapabilities'
|
||||
@@ -242,6 +243,9 @@
|
||||
$effect(() => {
|
||||
if (!dropdownOpen) keyArrowPos = undefined
|
||||
})
|
||||
// A picker left open in a pane that went off screen would take the next page's arrows, and
|
||||
// its Enter would pick a workspace there.
|
||||
const hostActive = overlayHostActive()
|
||||
|
||||
function activateRow(row: NavRow) {
|
||||
if (row.kind === 'create') {
|
||||
@@ -371,7 +375,7 @@
|
||||
|
||||
<svelte:window
|
||||
onkeydown={(e) => {
|
||||
if (!dropdownOpen) return
|
||||
if (!dropdownOpen || !hostActive()) return
|
||||
if (creatingFork) return
|
||||
if (navRows.length === 0) return
|
||||
if (e.key === 'ArrowDown') {
|
||||
|
||||
@@ -384,9 +384,23 @@ export const sessionState = $state<{
|
||||
// Keyed per session: a single shared timer would let a keystroke in one draft
|
||||
// cancel a sibling draft's pending flush, dropping that draft's first-touch write.
|
||||
const draftPromptFlushHandles = new Map<string, ReturnType<typeof setTimeout>>()
|
||||
|
||||
// The composer's unsent input in a session already sent, which a chat column mounted again
|
||||
// reads back: the composer's draft is component-local, and the sessions view unmounts on the
|
||||
// pages outside the logged layout (`/user/*`). Kept apart from `draftPrompt` and
|
||||
// `draftAttachments`, which hold the first message until the commit consumes it. In memory
|
||||
// only: a reload drops it.
|
||||
const sentSessionDraftText = new Map<string, string>()
|
||||
const sentSessionDraftAttachments = new Map<string, DraftAttachments>()
|
||||
|
||||
export function setSessionDraftPrompt(sessionId: string, text: string): void {
|
||||
const s = sessionState.sessions.find((x) => x.id === sessionId)
|
||||
if (!s || s.workspace_id) return
|
||||
if (!s) return
|
||||
if (s.workspace_id) {
|
||||
if (text === '') sentSessionDraftText.delete(sessionId)
|
||||
else sentSessionDraftText.set(sessionId, text)
|
||||
return
|
||||
}
|
||||
// No-op on an unchanged prompt, so opening an untouched draft never persists
|
||||
// it. Writes of '' are real edits (a draft typed then erased is still a
|
||||
// session), which is why the composer reports edits only — see AIChatInput.
|
||||
@@ -406,12 +420,10 @@ export function setSessionDraftPrompt(sessionId: string, text: string): void {
|
||||
)
|
||||
}
|
||||
|
||||
// Read back the persisted composer text when a pending session's chat mounts.
|
||||
// Returns nothing once the session is committed (its draft prompt was consumed).
|
||||
export function getSessionDraftPrompt(sessionId: string): string | undefined {
|
||||
const s = sessionState.sessions.find((x) => x.id === sessionId)
|
||||
if (!s || s.workspace_id) return undefined
|
||||
return s.draftPrompt
|
||||
if (!s) return undefined
|
||||
return s.workspace_id ? sentSessionDraftText.get(sessionId) : s.draftPrompt
|
||||
}
|
||||
|
||||
// The rest of an unsent draft (collapsed pastes, images, files), so a composer mounted again
|
||||
@@ -424,10 +436,15 @@ export function setSessionDraftAttachments(sessionId: string, attachments: Draft
|
||||
const empty = Object.values(attachments).every((lane) => lane.length === 0)
|
||||
if (empty) {
|
||||
draftAttachments.delete(sessionId)
|
||||
sentSessionDraftAttachments.delete(sessionId)
|
||||
return
|
||||
}
|
||||
const s = sessionState.sessions.find((x) => x.id === sessionId)
|
||||
if (!s || s.workspace_id) return
|
||||
if (!s) return
|
||||
if (s.workspace_id) {
|
||||
sentSessionDraftAttachments.set(sessionId, attachments)
|
||||
return
|
||||
}
|
||||
draftAttachments.set(sessionId, attachments)
|
||||
// Attaching is a touch, as typing is: a draft holding only an image would otherwise still
|
||||
// read as a blank, be reused by the next hand-off with the image in it, or be dropped.
|
||||
@@ -436,8 +453,10 @@ export function setSessionDraftAttachments(sessionId: string, attachments: Draft
|
||||
|
||||
export function getSessionDraftAttachments(sessionId: string): DraftAttachments | undefined {
|
||||
const s = sessionState.sessions.find((x) => x.id === sessionId)
|
||||
if (!s || s.workspace_id) return undefined
|
||||
return draftAttachments.get(sessionId)
|
||||
if (!s) return undefined
|
||||
return s.workspace_id
|
||||
? sentSessionDraftAttachments.get(sessionId)
|
||||
: draftAttachments.get(sessionId)
|
||||
}
|
||||
|
||||
// A hand-off arrives within a navigation; anything older than this is the debris
|
||||
@@ -1682,6 +1701,8 @@ export function deleteSession(id: string) {
|
||||
clearTimeout(draftPromptFlushHandles.get(id))
|
||||
draftPromptFlushHandles.delete(id)
|
||||
draftAttachments.delete(id)
|
||||
sentSessionDraftText.delete(id)
|
||||
sentSessionDraftAttachments.delete(id)
|
||||
sessionState.sessions = sessionState.sessions.filter((x) => x.id !== id)
|
||||
if (sessionState.currentSessionId === id) {
|
||||
sessionState.currentSessionId = sessionState.sessions[0]?.id
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
createSession,
|
||||
decideSessionLifecycle,
|
||||
getSessionDraftAttachments,
|
||||
getSessionDraftPrompt,
|
||||
holdHomeDraft,
|
||||
holdSessionUntilStarted,
|
||||
homeDraft,
|
||||
@@ -690,6 +691,34 @@ describe('createSession — reuses an untouched draft, family-scoped', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('composer draft of a sent session', () => {
|
||||
it('reads back the follow-up, never the first message, and empties with the composer', () => {
|
||||
sessionState.sessions.push(session({ id: 'sent-draft', draftPrompt: 'first message' }))
|
||||
const pastes = [{} as PasteAttachment]
|
||||
try {
|
||||
setSessionDraftAttachments('sent-draft', { ...NO_ATTACHMENTS, pastes })
|
||||
sessionState.sessions.find((x) => x.id === 'sent-draft')!.workspace_id = 'ws'
|
||||
// The record's draft prompt and the staged attachments are the first message: read
|
||||
// back after the send, they would put it in the composer a second time.
|
||||
expect(getSessionDraftPrompt('sent-draft')).toBeUndefined()
|
||||
expect(getSessionDraftAttachments('sent-draft')).toBeUndefined()
|
||||
|
||||
setSessionDraftPrompt('sent-draft', 'follow-up')
|
||||
setSessionDraftAttachments('sent-draft', { ...NO_ATTACHMENTS, pastes })
|
||||
expect(getSessionDraftPrompt('sent-draft')).toBe('follow-up')
|
||||
expect(getSessionDraftAttachments('sent-draft')).toEqual({ ...NO_ATTACHMENTS, pastes })
|
||||
|
||||
setSessionDraftPrompt('sent-draft', '')
|
||||
setSessionDraftAttachments('sent-draft', NO_ATTACHMENTS)
|
||||
expect(getSessionDraftPrompt('sent-draft')).toBeUndefined()
|
||||
expect(getSessionDraftAttachments('sent-draft')).toBeUndefined()
|
||||
} finally {
|
||||
setSessionDraftAttachments('sent-draft', NO_ATTACHMENTS)
|
||||
sessionState.sessions = sessionState.sessions.filter((s) => s.id !== 'sent-draft')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('withOpenSessionTeardown — the gate that holds recovery off during a delete', () => {
|
||||
it('stays shut until the outermost teardown finishes', async () => {
|
||||
let innerDone = false
|
||||
|
||||
@@ -978,6 +978,15 @@
|
||||
}
|
||||
|
||||
let devOnly = $derived(page.url.pathname.startsWith('/scripts/dev'))
|
||||
// The desktop rail is fixed-positioned, so the content is offset by its width (in rem).
|
||||
let contentInset = $derived(devOnly || menuHidden || useDrawer ? 0 : railWidth)
|
||||
// The sessions view is mounted once opened and then kept, hidden on other pages, so its
|
||||
// chats keep their scroll, composer and expanded tool cards when the user comes back.
|
||||
// Never in a preview iframe: it would nest the sessions UI, with its iframes, in itself.
|
||||
let sessionsViewOpened = false
|
||||
const sessionsViewRequested = $derived.by(
|
||||
() => (sessionsViewOpened ||= onSessionsPage && !embedded)
|
||||
)
|
||||
// A devops user who belongs to no workspace has no `$userStore`, and would otherwise wait on
|
||||
// "Loading user..." forever on the instance pages their role exists for.
|
||||
let instanceOnlyView = $derived(
|
||||
@@ -1739,17 +1748,45 @@ outside this layout, and their shortcut must reopen the URL that is their creden
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
<!-- The scroll lives here, below the page header: a page taller than the window scrolls
|
||||
inside this box, so the band stays on screen instead of leaving with the content. The
|
||||
desktop rail is fixed-positioned, so the content is offset by its width (in rem). -->
|
||||
<div
|
||||
id="content"
|
||||
class={classNames('flex-1 min-h-0 flex flex-col overflow-y-auto', sidebarTransitionClass)}
|
||||
style:padding-left="{devOnly || menuHidden || useDrawer ? 0 : railWidth}rem"
|
||||
>
|
||||
<div class="flex-1 min-h-0 flex flex-col">
|
||||
{@render children?.()}
|
||||
<!-- The sessions view shares the content's cell. A grid rather than a positioned box,
|
||||
which would become the containing block of every page's absolute descendants.
|
||||
Hidden, the view keeps its size, so its transcripts neither reflow nor lose their
|
||||
scroll; it eases only its inset, as a fade between pages would paint it over the
|
||||
next one. -->
|
||||
<div class="flex-1 min-h-0 grid grid-cols-1 grid-rows-1">
|
||||
<!-- The scroll lives here, below the page header: a page taller than the window scrolls
|
||||
inside this box, so the band stays on screen instead of leaving with the content. -->
|
||||
<div
|
||||
id="content"
|
||||
class={classNames(
|
||||
'col-start-1 row-start-1 min-h-0 flex flex-col overflow-y-auto',
|
||||
sidebarTransitionClass
|
||||
)}
|
||||
style:padding-left="{contentInset}rem"
|
||||
>
|
||||
<div class="flex-1 min-h-0 flex flex-col">
|
||||
{@render children?.()}
|
||||
</div>
|
||||
</div>
|
||||
{#if sessionsViewRequested}
|
||||
<!-- Off route, content-visibility skips the style and layout work that `invisible`
|
||||
leaves running: a reply streaming into a hidden transcript would pay it per chunk. -->
|
||||
<div
|
||||
class={classNames(
|
||||
'col-start-1 row-start-1 min-h-0 flex flex-col overflow-y-auto',
|
||||
sidebarTransitionClass ? 'transition-[padding-left] duration-200 ease-in-out' : '',
|
||||
onSessionsPage ? '' : 'invisible opacity-0 [content-visibility:hidden]'
|
||||
)}
|
||||
inert={!onSessionsPage}
|
||||
style:padding-left="{contentInset}rem"
|
||||
>
|
||||
<div class="flex-1 min-h-0 flex flex-col">
|
||||
{#await import('$lib/components/sessions/SessionsView.svelte') then SessionsView}
|
||||
<SessionsView.default shown={onSessionsPage} />
|
||||
{/await}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user