Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139<script lang="ts"> import { mount, untrack, type Component } from 'svelte'; import { windowData, type Board, type Window, type WindowType, } from '../board.svelte'; import ChipNode from '../nodes/ChipNode.svelte'; import { loaders, type Eager } from '../nodes/loaders'; import NoteNode from '../nodes/NoteNode.svelte'; import SessionNode from '../nodes/SessionNode.svelte'; import { hosted } from './hosts'; import LazyWindow from './LazyWindow.svelte';
// Where a window shows: a tile, a tab, a spot on a canvas. The window is // mounted once (hosts.ts) and carried from slot to slot, so moving it // keeps its scroll, its page and its shell. A window off a canvas filling // the board is shown in BoardView's own slot (`over`), its place on the // canvas left empty until it goes back. let { board, window, tile, over = false, }: { board: Board; window: string; tile?: string; over?: boolean } = $props();
// A chat, a note and a chip are there from the start; every other window loads on first use (nodes/loaders.ts). const eager: Record<Eager, Component<any>> = { session: SessionNode, note: NoteNode, chip: ChipNode, };
const type = $derived(board.windows[window]?.type); /** Marked as the one keys act on, unless it is the only tile filling the board; a note marks itself. */ const away = $derived( !over && board.expandedOver && board.expanded === window, ); const marked = $derived( board.selected === window && type !== 'note' && board.root.kind !== 'leaf', );
let slot = $state<HTMLElement>();
/** * Selects this window when a frame inside it (an artifact's page) takes the * focus. A press in a frame reaches neither handler on the slot: this * window only blurs, and the frame may become the active element after. */ function framed() { setTimeout(() => { const focused = document.activeElement; if ( focused instanceof HTMLIFrameElement && slot?.contains(focused) && board.selected !== window ) board.select(window); }); }
function make(owner: Board, id: string) { return (target: HTMLElement) => untrack(() => { // A closed window stays mounted until its host is swept, a frame later, still showing what it last held. let data: Window['data'] = owner.windows[id].data; const current = windowData(owner, id); const props = { id, get data() { return (data = current() ?? data); }, get selected() { return owner.selected === id; }, }; const kind = owner.windows[id].type; if (kind in eager) return mount(eager[kind as Eager], { target, props }); return mount(LazyWindow, { target, props: { load: loaders[kind as Exclude<WindowType, Eager>], props }, }); }); }</script>
<svelte:window onblur={framed} />
{#if type} <div bind:this={slot} class="window-slot" class:picked={board.picked.has(window)} class:selected={marked} data-id={window} data-tile={tile} data-type={type} data-place={over ? 'tile' : board.placeOf(window)} onpointerdowncapture={() => board.select(window)} onfocusin={() => board.selected !== window && board.select(window)} {@attach away ? null : hosted(board.id, window, make(board, window))} ></div>{/if}
<style> /* Its own stacking context, so nothing inside a window climbs over a floating note; a window with a menu open is lifted so the menu can hang over its neighbours and the notes. */ .window-slot { position: relative; z-index: var(--z-window); width: 100%; height: 100%; border-radius: 14px; } .window-slot:has(:global([aria-haspopup][aria-expanded='true'])) { z-index: var(--z-window-menu); } /* Every mark on a window (selected, picked, a flash) is drawn on the slot, never on the window's frame: the window's own layers (its title bar, its menus) stay inside its host, so a mark lies over all of it. */ .window-slot > :global(.window-host) { isolation: isolate; } /* flash() in board.svelte.ts animates it in. */ .window-slot::before { position: absolute; inset: 0; z-index: 1; border: 2px solid var(--accent); border-radius: 14px; opacity: 0; content: ''; pointer-events: none; }</style>