fix(ui): keep the YAML gutter aligned on phones and fit the editor to a phone viewport
The gutter printed one number per source line while the text layer wrapped, so every line after a long one was numbered wrong. The textarea no longer wraps: the gutter, the highlight layer and the textarea share one row per line and scroll together on both axes. Below md the section tabs that do not fit collapse into one menu that sets the same tab, and the actions share one right-aligned row. The canvas is sized to the viewport left on a phone, frames a graph or card wider than the canvas instead of clipping its edges, and clears the chat launcher.
This commit is contained in:
1 parent
185ecd09ee
commit
72e65645eb
4 files changed
+120
-66
No files matched your search
@@ -176,9 +176,36 @@ const edges = computed(() =>
|
||||
);
|
||||
|
||||
const ZOOM = 0.9;
|
||||
// Clearance from the canvas edges for the graph, so a fitted graph does not
|
||||
// touch them.
|
||||
const PAD = 20;
|
||||
let flow: VueFlowStore | undefined;
|
||||
const top = computed(() => (editable.value ? TOP : 0));
|
||||
|
||||
// The graph's horizontal extent, in canvas units: a lane is wider than the card
|
||||
// it holds, and a card opened in place is wider still.
|
||||
function extent(): { left: number; width: number } {
|
||||
let left = Infinity;
|
||||
let right = -Infinity;
|
||||
for (const node of nodes.value) {
|
||||
// An insertion point is a glyph, not a card, and it sits inside the extent
|
||||
// of the cards around it.
|
||||
if (node.type !== "step" && node.type !== "lane") continue;
|
||||
const width = node.style?.width ? parseFloat(String(node.style.width)) : node.id === anchor.value?.id ? OPEN_WIDTH : NODE_WIDTH;
|
||||
left = Math.min(left, node.position.x);
|
||||
right = Math.max(right, node.position.x + width);
|
||||
}
|
||||
return Number.isFinite(left) ? { left, width: right - left } : { left: 0, width: NODE_WIDTH };
|
||||
}
|
||||
|
||||
// The scale and left offset that place the graph's whole extent inside the
|
||||
// canvas with clearance at both edges, at no more than the readable size.
|
||||
function framing(width: number): { x: number; zoom: number } {
|
||||
const { left, width: span } = extent();
|
||||
const zoom = Math.max(0.3, Math.min(ZOOM, (width - PAD * 2) / span));
|
||||
return { x: width / 2 - (left + span / 2) * zoom, zoom };
|
||||
}
|
||||
|
||||
// Start at a readable size rather than shrinking a long workflow until
|
||||
// nothing on it can be read, scrolled to the furthest step the watched run has
|
||||
// reached so the step that is moving stays in view.
|
||||
@@ -188,23 +215,28 @@ function place(store?: VueFlowStore): void {
|
||||
if (!flow) return;
|
||||
const width = container.value?.clientWidth ?? 800;
|
||||
const height = container.value?.clientHeight ?? 560;
|
||||
const { x, zoom } = framing(width);
|
||||
// Scroll only when the furthest step reached would be out of view.
|
||||
const reached = graph.value.nodes.find((node) => props.marks?.[node.id]) ?? graph.value.nodes.filter((node) => node.data.run).at(-1);
|
||||
const below = reached && 24 + (reached.position.y - top.value + 180) * ZOOM > height;
|
||||
const y = below ? height / 3 - reached.position.y * ZOOM : 24 - top.value * ZOOM;
|
||||
void flow.setViewport({ x: width / 2 - NODE_WIDTH * ZOOM / 2, y, zoom: ZOOM }, { duration: animate ? 300 : 0 });
|
||||
const below = reached && 24 + (reached.position.y - top.value + 180) * zoom > height;
|
||||
const y = below ? height / 3 - reached.position.y * zoom : 24 - top.value * zoom;
|
||||
void flow.setViewport({ x, y, zoom }, { duration: animate ? 300 : 0 });
|
||||
}
|
||||
|
||||
watch(() => graph.value.nodes.filter((node) => node.data.run).length, () => place());
|
||||
watch(() => props.marks, () => place());
|
||||
// A card opened low on the canvas scrolls up so its form is in view.
|
||||
// A card opened low on the canvas scrolls up so its form is in view, and one
|
||||
// opened wider than the canvas allows is framed so its edges stay reachable.
|
||||
watch(anchor, async (node) => {
|
||||
await nextTick();
|
||||
if (!node || !flow) return;
|
||||
const { x, y, zoom } = flow.getViewport();
|
||||
const screenTop = (node.position.y + pushed(node.position.y)) * zoom + y;
|
||||
const { y } = flow.getViewport();
|
||||
const width = container.value?.clientWidth ?? 800;
|
||||
const height = container.value?.clientHeight ?? 560;
|
||||
if (screenTop < 8 || screenTop > height / 2) void flow.setViewport({ x, y: y - screenTop + 24, zoom }, { duration: 250 });
|
||||
const { x, zoom } = framing(width);
|
||||
const screenTop = (node.position.y + pushed(node.position.y)) * zoom + y;
|
||||
const away = screenTop < 8 || screenTop > height / 2;
|
||||
void flow.setViewport({ x, y: away ? y - screenTop + 24 : y, zoom }, { duration: 250 });
|
||||
});
|
||||
|
||||
// The right-click menu opens at the pointer, for the step under it or for the
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { computed, onBeforeUnmount, ref, watch } from "vue";
|
||||
import { Ellipsis, RotateCcw, Trash2 } from "@lucide/vue";
|
||||
import { ChevronDown, Ellipsis, RotateCcw, Trash2 } from "@lucide/vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
@@ -339,12 +339,16 @@ const runOptions = computed(() => [
|
||||
})),
|
||||
]);
|
||||
const lines = computed(() => yamlLines(yaml.value));
|
||||
// Below md the section tabs that do not fit beside Canvas and YAML are picked
|
||||
// from one menu, which also names the section in view.
|
||||
const OVERFLOW: Record<string, string> = { history: "History", performance: "Performance", runs: "Runs" };
|
||||
|
||||
// The highlight layer sits behind the textarea and never scrolls by itself, so
|
||||
// it follows the textarea's own scroll.
|
||||
const scrolled = ref(0);
|
||||
// it follows the textarea's own scroll on both axes.
|
||||
const scrolled = ref({ top: 0, left: 0 });
|
||||
function syncScroll(event: Event): void {
|
||||
scrolled.value = (event.target as HTMLTextAreaElement).scrollTop;
|
||||
const { scrollTop, scrollLeft } = event.target as HTMLTextAreaElement;
|
||||
scrolled.value = { top: scrollTop, left: scrollLeft };
|
||||
}
|
||||
|
||||
</script>
|
||||
@@ -353,13 +357,25 @@ function syncScroll(event: Event): void {
|
||||
<form class="space-y-4" @submit.prevent="publish">
|
||||
<Tabs v-model="view" class="space-y-1.5">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<TabsList class="max-w-full justify-start overflow-x-auto">
|
||||
<TabsList class="max-w-full justify-start">
|
||||
<TabsTrigger value="canvas">Canvas</TabsTrigger>
|
||||
<TabsTrigger value="yaml">YAML</TabsTrigger>
|
||||
<TabsTrigger v-if="stored !== undefined" value="history">History</TabsTrigger>
|
||||
<TabsTrigger v-if="$slots.performance" value="performance">Performance</TabsTrigger>
|
||||
<TabsTrigger v-if="$slots.runs" value="runs">Runs <span class="ml-1 font-mono text-xs text-fg-subtle">{{ runsCount ?? 0 }}</span></TabsTrigger>
|
||||
<TabsTrigger v-if="stored !== undefined" value="history" class="max-md:hidden">History</TabsTrigger>
|
||||
<TabsTrigger v-if="$slots.performance" value="performance" class="max-md:hidden">Performance</TabsTrigger>
|
||||
<TabsTrigger v-if="$slots.runs" value="runs" class="max-md:hidden">Runs <span class="ml-1 font-mono text-xs text-fg-subtle">{{ runsCount ?? 0 }}</span></TabsTrigger>
|
||||
</TabsList>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger as-child>
|
||||
<Button type="button" variant="outline" size="sm" class="md:hidden" aria-label="More sections">
|
||||
{{ OVERFLOW[view] ?? "More" }}<ChevronDown data-icon="inline-end" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start" class="w-40">
|
||||
<DropdownMenuItem v-if="stored !== undefined" @select="view = 'history'">History</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="$slots.performance" @select="view = 'performance'">Performance</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="$slots.runs" @select="view = 'runs'">Runs <span class="ml-auto font-mono text-xs text-fg-subtle">{{ runsCount ?? 0 }}</span></DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<div v-if="runs.length && view === 'canvas'" class="flex min-w-0 items-center gap-1">
|
||||
<OptionSelect :model-value="watched" :options="runOptions" aria-label="Run shown on the canvas" class="min-w-0 max-w-64" @update:model-value="pick" />
|
||||
<template v-if="watchedRun">
|
||||
@@ -369,34 +385,35 @@ function syncScroll(event: Event): void {
|
||||
</template>
|
||||
</div>
|
||||
<template v-if="view === 'canvas' || view === 'yaml'">
|
||||
<span v-if="!parsed.ok" class="ml-auto max-w-md truncate text-xs text-danger" role="status" :title="validationLabel(parsed)">
|
||||
{{ validationLabel(parsed) }}
|
||||
</span>
|
||||
<Popover v-else-if="dirty">
|
||||
<PopoverTrigger as-child>
|
||||
<Button type="button" variant="ghost" size="sm" class="ml-auto text-xs text-fg-subtle">
|
||||
Draft · {{ changes.length }} {{ changes.length === 1 ? "change" : "changes" }}</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent align="end" class="max-h-96 w-96 overflow-y-auto p-0">
|
||||
<ChangeList :changes="changes" @revert="(change) => (yaml = revertWorkflowChange(yaml, change))" />
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<span v-else class="ml-auto" />
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger as-child>
|
||||
<Button type="button" variant="ghost" size="icon-sm" aria-label="More"><Ellipsis /></Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" class="w-48">
|
||||
<DropdownMenuItem v-if="dirty" :disabled="archieWorking" @select="discard"><RotateCcw />Discard draft</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="shippedEntry" @select="restoreOne"><RotateCcw />Restore Defaults</DropdownMenuItem>
|
||||
<DropdownMenuSeparator v-if="dirty || shippedEntry" />
|
||||
<DropdownMenuItem variant="destructive" @select="confirmDelete = true"><Trash2 />Delete workflow</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<RunWorkflowButton v-if="stored !== undefined" :workflow="selected" :draft="yaml" :disabled="!parsed.ok" @started="(id) => { view = 'canvas'; void follow(id); }" />
|
||||
<RunWorkflowButton v-if="stored !== undefined" :workflow="selected" :disabled="dirty" @started="(id) => { view = 'canvas'; void follow(id); }" />
|
||||
<Button type="submit" size="sm" :disabled="state.saving || !parsed.ok || !dirty || archieWorking">
|
||||
<Spinner v-if="state.saving" data-icon="inline-start" />Publish</Button>
|
||||
<div class="ml-auto flex flex-wrap items-center justify-end gap-2">
|
||||
<span v-if="!parsed.ok" class="max-w-md truncate text-xs text-danger" role="status" :title="validationLabel(parsed)">
|
||||
{{ validationLabel(parsed) }}
|
||||
</span>
|
||||
<Popover v-else-if="dirty">
|
||||
<PopoverTrigger as-child>
|
||||
<Button type="button" variant="ghost" size="sm" class="text-xs text-fg-subtle">
|
||||
Draft · {{ changes.length }} {{ changes.length === 1 ? "change" : "changes" }}</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent align="end" class="max-h-96 w-96 overflow-y-auto p-0">
|
||||
<ChangeList :changes="changes" @revert="(change) => (yaml = revertWorkflowChange(yaml, change))" />
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger as-child>
|
||||
<Button type="button" variant="ghost" size="icon-sm" aria-label="More"><Ellipsis /></Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" class="w-48">
|
||||
<DropdownMenuItem v-if="dirty" :disabled="archieWorking" @select="discard"><RotateCcw />Discard draft</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="shippedEntry" @select="restoreOne"><RotateCcw />Restore Defaults</DropdownMenuItem>
|
||||
<DropdownMenuSeparator v-if="dirty || shippedEntry" />
|
||||
<DropdownMenuItem variant="destructive" @select="confirmDelete = true"><Trash2 />Delete workflow</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<RunWorkflowButton v-if="stored !== undefined" :workflow="selected" :draft="yaml" :disabled="!parsed.ok" @started="(id) => { view = 'canvas'; void follow(id); }" />
|
||||
<RunWorkflowButton v-if="stored !== undefined" :workflow="selected" :disabled="dirty" @started="(id) => { view = 'canvas'; void follow(id); }" />
|
||||
<Button type="submit" size="sm" :disabled="state.saving || !parsed.ok || !dirty || archieWorking">
|
||||
<Spinner v-if="state.saving" data-icon="inline-start" />Publish</Button>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<p v-if="runsLoading && !runs.length" class="text-xs text-fg-muted" role="status">Loading recent runs…</p>
|
||||
@@ -409,8 +426,10 @@ function syncScroll(event: Event): void {
|
||||
editor and loads its draft when the operator switches tabs. -->
|
||||
<TabsContent value="canvas" force-mount class="space-y-2 data-[state=inactive]:hidden">
|
||||
<!-- The canvas takes the height the viewport has left, so the page
|
||||
itself does not scroll; the canvas pans. -->
|
||||
<div class="relative h-[calc(100dvh-17rem)] min-h-[26rem]">
|
||||
itself does not scroll; the canvas pans. A phone stacks more chrome
|
||||
above it (the workflow list, a two-row toolbar and the run picker),
|
||||
hence the larger offset below md. -->
|
||||
<div class="relative h-[calc(100dvh-17rem)] min-h-[26rem] max-md:h-[calc(100dvh-30rem)] max-md:min-h-[20rem]">
|
||||
<p v-if="restartError" role="alert" class="absolute bottom-3 left-14 z-10 max-w-xl rounded-md border border-danger/40 bg-card px-3 py-2 text-sm text-danger shadow-lg">{{ restartError }}</p>
|
||||
<WorkflowCanvas
|
||||
:inert="archieWorking"
|
||||
@@ -454,7 +473,7 @@ function syncScroll(event: Event): void {
|
||||
</template>
|
||||
</template>
|
||||
</WorkflowCanvas>
|
||||
<div class="pointer-events-none absolute inset-x-0 bottom-3 z-10 flex justify-center px-3">
|
||||
<div class="pointer-events-none absolute inset-x-0 bottom-3 z-10 flex justify-center px-3 max-md:pr-20">
|
||||
<CoBuilder
|
||||
v-if="selected"
|
||||
:key="selected"
|
||||
@@ -487,7 +506,7 @@ function syncScroll(event: Event): void {
|
||||
aria-hidden="true"
|
||||
class="pointer-events-none absolute inset-y-0 left-0 w-11 select-none overflow-hidden border-r border-border bg-secondary/40 py-3 text-right"
|
||||
>
|
||||
<div :style="`transform:translateY(${-scrolled}px)`">
|
||||
<div :style="`transform:translateY(${-scrolled.top}px)`">
|
||||
<div
|
||||
v-for="line in lines"
|
||||
:key="line.number"
|
||||
@@ -496,11 +515,13 @@ function syncScroll(event: Event): void {
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Clipped to the right of the gutter, so a line scrolled left never
|
||||
paints over the numbers. -->
|
||||
<div
|
||||
aria-hidden="true"
|
||||
class="pointer-events-none absolute inset-0 overflow-hidden py-3 pr-3 pl-14 break-words whitespace-pre-wrap"
|
||||
class="pointer-events-none absolute inset-y-0 right-0 left-11 overflow-hidden py-3 pr-3 pl-3 whitespace-pre"
|
||||
>
|
||||
<div :style="`transform:translateY(${-scrolled}px)`">
|
||||
<div :style="`transform:translate(${-scrolled.left}px,${-scrolled.top}px)`">
|
||||
<div v-for="line in lines" :key="line.number" class="min-h-6">
|
||||
<span
|
||||
v-for="(token, i) in line.tokens"
|
||||
@@ -519,6 +540,7 @@ function syncScroll(event: Event): void {
|
||||
required
|
||||
class="relative min-h-96 resize-y rounded-none border-0 bg-transparent py-3 pr-3 pl-14 text-[13px] leading-6 text-transparent caret-foreground shadow-none md:text-[13px] focus-visible:ring-0"
|
||||
spellcheck="false"
|
||||
wrap="off"
|
||||
@scroll="syncScroll"
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user