feat(ui): wrap the YAML editor at the pane or a set print width, with an appearance setting
This commit is contained in:
1 parent
b47f768076
commit
35e9d5d64e
5 files changed
+206
-131
No files matched your search
@@ -7,14 +7,16 @@ import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
|
||||
import {
|
||||
type Density,
|
||||
type Motion,
|
||||
PRINT_WIDTHS,
|
||||
type PrintWidth,
|
||||
type Theme,
|
||||
useAppearanceStore,
|
||||
} from "@/stores/appearance";
|
||||
import ConfigCard from "./ConfigCard.vue";
|
||||
|
||||
const appearance = useAppearanceStore();
|
||||
const { density, motion, overscroll, theme, tooltipsEnabled } = storeToRefs(appearance);
|
||||
const { setDensity, setMotion, setOverscroll, setTheme, setTooltips } = appearance;
|
||||
const { density, motion, overscroll, printWidth, theme, tooltipsEnabled } = storeToRefs(appearance);
|
||||
const { setDensity, setMotion, setOverscroll, setPrintWidth, setTheme, setTooltips } = appearance;
|
||||
|
||||
/**
|
||||
* Appearance: how the dashboard looks, on this browser. These preferences are
|
||||
@@ -30,6 +32,10 @@ function chooseDensity(value: unknown): void {
|
||||
setDensity(value as Density);
|
||||
}
|
||||
|
||||
function choosePrintWidth(value: unknown): void {
|
||||
if (PRINT_WIDTHS.includes(value as PrintWidth)) setPrintWidth(value as PrintWidth);
|
||||
}
|
||||
|
||||
function chooseMotion(value: unknown): void {
|
||||
if (value === "system" || value === "reduced") setMotion(value as Motion);
|
||||
}
|
||||
@@ -42,7 +48,7 @@ function chooseMotion(value: unknown): void {
|
||||
<ConfigCard
|
||||
title="Dashboard preferences"
|
||||
>
|
||||
<div class="grid gap-8 md:grid-cols-2 lg:grid-cols-5">
|
||||
<div class="grid gap-8 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-6">
|
||||
<section class="flex min-w-0 flex-col items-start">
|
||||
<div>
|
||||
<h2 id="appearance-theme" class="text-sm font-medium">Theme</h2>
|
||||
@@ -118,6 +124,25 @@ function chooseMotion(value: unknown): void {
|
||||
@update:model-value="setOverscroll"
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section class="flex min-w-0 flex-col items-start">
|
||||
<div>
|
||||
<h2 id="appearance-print-width" class="text-sm font-medium">Print width</h2>
|
||||
</div>
|
||||
<ToggleGroup
|
||||
type="single"
|
||||
variant="outline"
|
||||
:model-value="printWidth"
|
||||
class="mt-4"
|
||||
aria-labelledby="appearance-print-width"
|
||||
@update:model-value="choosePrintWidth"
|
||||
>
|
||||
<ToggleGroupItem value="window">Window</ToggleGroupItem>
|
||||
<ToggleGroupItem value="80">80</ToggleGroupItem>
|
||||
<ToggleGroupItem value="100">100</ToggleGroupItem>
|
||||
<ToggleGroupItem value="120">120</ToggleGroupItem>
|
||||
</ToggleGroup>
|
||||
</section>
|
||||
</div>
|
||||
</ConfigCard>
|
||||
</div>
|
||||
|
||||
@@ -6,11 +6,16 @@ export const DENSITY_KEY = "archie.density";
|
||||
export const MOTION_KEY = "archie.motion";
|
||||
export const TOOLTIPS_KEY = "archie.tooltips";
|
||||
export const OVERSCROLL_KEY = "archie.overscroll";
|
||||
export const PRINT_WIDTH_KEY = "archie.printWidth";
|
||||
|
||||
export type Theme = "system" | "dark" | "light";
|
||||
export type Density = "comfortable" | "compact";
|
||||
export type Motion = "system" | "reduced";
|
||||
|
||||
/** Columns a code view wraps at; "window" wraps at the edge of the pane. */
|
||||
export type PrintWidth = "window" | "80" | "100" | "120";
|
||||
export const PRINT_WIDTHS: readonly PrintWidth[] = ["window", "80", "100", "120"];
|
||||
|
||||
type ResolvedTheme = Exclude<Theme, "system">;
|
||||
|
||||
function storedChoice<T extends string>(
|
||||
@@ -61,6 +66,9 @@ export const useAppearanceStore = defineStore("appearance", () => {
|
||||
const overscroll = ref(
|
||||
storedChoice(OVERSCROLL_KEY, ["on", "off"], "on") === "on",
|
||||
);
|
||||
const printWidth = ref<PrintWidth>(
|
||||
storedChoice(PRINT_WIDTH_KEY, PRINT_WIDTHS, "window"),
|
||||
);
|
||||
let initialized = false;
|
||||
|
||||
function applyTheme(): void {
|
||||
@@ -100,11 +108,25 @@ export const useAppearanceStore = defineStore("appearance", () => {
|
||||
persist(OVERSCROLL_KEY, enabled ? "on" : "off");
|
||||
}
|
||||
|
||||
function applyPrintWidth(): void {
|
||||
document.documentElement.style.setProperty(
|
||||
"--code-print-width",
|
||||
printWidth.value === "window" ? "9999ch" : `${printWidth.value}ch`,
|
||||
);
|
||||
}
|
||||
|
||||
function setPrintWidth(value: PrintWidth): void {
|
||||
printWidth.value = value;
|
||||
applyPrintWidth();
|
||||
persist(PRINT_WIDTH_KEY, value);
|
||||
}
|
||||
|
||||
function initialize(): void {
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
applyTheme();
|
||||
applyOverscroll();
|
||||
applyPrintWidth();
|
||||
document.documentElement.dataset.density = density.value;
|
||||
document.documentElement.dataset.motion = motion.value;
|
||||
try {
|
||||
@@ -125,11 +147,13 @@ export const useAppearanceStore = defineStore("appearance", () => {
|
||||
motion,
|
||||
tooltipsEnabled,
|
||||
overscroll,
|
||||
printWidth,
|
||||
initialize,
|
||||
setTheme,
|
||||
setDensity,
|
||||
setMotion,
|
||||
setTooltips,
|
||||
setOverscroll,
|
||||
setPrintWidth,
|
||||
};
|
||||
});
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
||||
import { CircleAlert, Ellipsis, RotateCcw, Trash2 } from "@lucide/vue";
|
||||
import { isSending, setTurnHooks } from "@/chat/state";
|
||||
|
||||
@@ -354,12 +354,35 @@ const lines = computed(() => yamlLines(yaml.value));
|
||||
const SECTIONS: 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 on both axes.
|
||||
const scrolled = ref({ top: 0, left: 0 });
|
||||
// it follows the textarea's own scroll. Lines wrap at the editor's width, and
|
||||
// each wrapped line's gutter cell lists a continuation mark per extra row, so
|
||||
// the numbers still count lines of the file. A row's wrapped height is measured
|
||||
// from the layer, which breaks exactly where the textarea does.
|
||||
const scrolled = ref({ top: 0 });
|
||||
const scrollbar = ref(0);
|
||||
const rowEls = ref<HTMLElement[]>([]);
|
||||
const wraps = ref<number[]>([]);
|
||||
const yamlBox = ref<InstanceType<typeof Textarea> | null>(null);
|
||||
function syncScroll(event: Event): void {
|
||||
const { scrollTop, scrollLeft } = event.target as HTMLTextAreaElement;
|
||||
scrolled.value = { top: scrollTop, left: scrollLeft };
|
||||
scrolled.value = { top: (event.target as HTMLTextAreaElement).scrollTop };
|
||||
}
|
||||
function measureWraps(): void {
|
||||
const field = document.getElementById("workflow-yaml");
|
||||
scrollbar.value = field ? field.offsetWidth - field.clientWidth : 0;
|
||||
wraps.value = rowEls.value.map((row) =>
|
||||
Math.max(1, Math.round(row.offsetHeight / (parseFloat(getComputedStyle(row).lineHeight) || 24))),
|
||||
);
|
||||
}
|
||||
let yamlObserver: ResizeObserver | undefined;
|
||||
watch(yamlBox, (box) => {
|
||||
yamlObserver?.disconnect();
|
||||
const field = box ? document.getElementById("workflow-yaml") : null;
|
||||
if (!field) return;
|
||||
yamlObserver = new ResizeObserver(measureWraps);
|
||||
yamlObserver.observe(field);
|
||||
});
|
||||
watch(lines, () => nextTick(measureWraps), { flush: "post" });
|
||||
onBeforeUnmount(() => yamlObserver?.disconnect());
|
||||
|
||||
</script>
|
||||
|
||||
@@ -509,44 +532,47 @@ function syncScroll(event: Event): void {
|
||||
>
|
||||
<div
|
||||
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"
|
||||
class="pointer-events-none absolute inset-y-0 left-0 w-11 select-none border-r border-border bg-secondary/40"
|
||||
></div>
|
||||
<div
|
||||
aria-hidden="true"
|
||||
class="pointer-events-none absolute inset-0 overflow-hidden py-3 pr-3"
|
||||
:style="{ paddingRight: `calc(0.75rem + ${scrollbar}px)` }"
|
||||
>
|
||||
<div :style="`transform:translateY(${-scrolled.top}px)`">
|
||||
<div
|
||||
v-for="line in lines"
|
||||
v-for="(line, i) in lines"
|
||||
:key="line.number"
|
||||
class="min-h-6 pr-2 text-fg-subtle"
|
||||
>{{ line.number }}</div
|
||||
:ref="(el) => { if (el) rowEls[i] = el as HTMLElement }"
|
||||
class="flex min-h-6"
|
||||
>
|
||||
</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-y-0 right-0 left-11 overflow-hidden py-3 pr-3 pl-3 whitespace-pre"
|
||||
>
|
||||
<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"
|
||||
:key="i"
|
||||
:class="yamlTokenClass(token.kind)"
|
||||
>{{ token.text }}</span
|
||||
>
|
||||
<div class="w-11 shrink-0 select-none pr-2 text-right text-fg-subtle">
|
||||
<div>{{ line.number }}</div>
|
||||
<div v-for="n in (wraps[i] ?? 1) - 1" :key="n">↳</div>
|
||||
</div>
|
||||
<div class="max-w-[calc(var(--code-print-width)+0.75rem)] min-w-0 flex-1 pl-3 break-words whitespace-pre-wrap">
|
||||
<span
|
||||
v-for="(token, j) in line.tokens"
|
||||
:key="j"
|
||||
:class="yamlTokenClass(token.kind)"
|
||||
>{{ token.text }}</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Textarea
|
||||
id="workflow-yaml"
|
||||
ref="yamlBox"
|
||||
aria-label="Workflow YAML"
|
||||
v-model="yaml"
|
||||
name="workflow-yaml"
|
||||
required
|
||||
:readonly="archieWorking"
|
||||
class="relative min-h-96 resize-y max-md:h-full max-md:min-h-0 max-md:resize-none rounded-none border-0 bg-transparent pt-3 pr-3 pb-[calc(0.75rem+var(--code-overscroll))] pl-14 text-[13px] leading-6 text-transparent caret-foreground shadow-none md:text-[13px] focus-visible:ring-0"
|
||||
class="relative min-h-96 resize-y max-md:h-full max-md:min-h-0 max-md:resize-none rounded-none border-0 bg-transparent pt-3 pr-3 pb-[calc(0.75rem+var(--code-overscroll))] pl-14 text-[13px] leading-6 break-words whitespace-pre-wrap text-transparent caret-foreground shadow-none md:text-[13px] focus-visible:ring-0"
|
||||
spellcheck="false"
|
||||
wrap="off"
|
||||
wrap="soft"
|
||||
:style="{ maxWidth: `calc(3.5rem + var(--code-print-width) + 0.75rem + ${scrollbar}px)` }"
|
||||
@scroll="syncScroll"
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user