Files
FabledScribe/frontend/src/views/SnippetDetailView.vue
T
bvandeusenandClaude Opus 5 d0a2733cb6
CI & Build / Plugin hooks (push) Successful in 11s
CI & Build / Python lint (push) Successful in 3s
CI & Build / TypeScript typecheck (push) Successful in 36s
CI & Build / integration (push) Successful in 34s
CI & Build / Python tests (push) Successful in 1m12s
CI & Build / Build & push image (push) Successful in 1m2s
fix(design): text on a tint of itself now clears AA app-wide, and the check gates it (#3141)
The badge fix (#3132) exposed the same defect everywhere: 48 rules painting a
token as TEXT on an inline color-mix tint of that same token. Worst raw
measurements, across every tint strength in use, both modes, over
page/raised/hover:

  accent 1.53:1 · success 1.67:1 · text-tertiary 2.15:1
  warning 2.32:1 · error 2.36:1                        against AA's 4.5

THE DEFECT IS IN THE HOUSE, NOT IN SCRIBE. The semantic hues are shared
family-wide, and the accent case was measured against every app's real
accent, not assumed from Scribe's: Minstrel 1.81, Forge 1.87, Steward 1.65,
Roundtable 3.01 — all failing. So the six -fg tokens are recorded on
FabledSword (design system 1), where their parents live, rather than copied
into each app.

45% toward --fs-text-primary clears AA for ALL FIVE accents (4.56-5.00), so
this is one house token rather than five overrides, and it keeps deriving
from --fs-accent — an app that overrides its accent still gets a legible
tinted-text colour in its own colour, the same mechanism as
--fs-accent-soft. The tokens are additive: a sibling app is unaffected until
it regenerates its own stylesheet.

One token is honestly redundant. --fs-text-secondary already passes at
4.82:1, and --fs-text-secondary-fg barely moves it. It exists so the rule
has NO exceptions, because the alternative is a permanent allow-list entry
for the one case that happens to pass — and a guard with an invisible
exception is a guard that erodes.

46 substitutions across 18 files, each rewriting only the `color:` inside a
block that tints its own background.

THE CHECK NOW GATES BOTH SPELLINGS. It previously reported the inline form,
because a gate nobody can satisfy on the day it lands gets switched off.
Both are clean, so both fail the build now.

And the check had a false-positive bug worth naming: its `color\s*:` regex
matched the tail of `border-color`, `border-left-color` and `outline-color`,
so it flagged seven rules that were already correct. A border is a non-text
graphic with a 3:1 floor, not text at 4.5. A check that cries wolf on
correct code is one that gets muted, so that mattered more than the noise.

Verified by construction, not by passing: reintroduced each defect form
(exit 1 each), and confirmed a legitimate border-only rule still exits 0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 21:38:09 -04:00

411 lines
11 KiB
Vue

<script setup lang="ts">
import { ref, computed, onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";
import {
getSnippet,
deleteSnippet,
unmergeSnippet,
type Snippet,
} from "@/api/snippets";
import { useToastStore } from "@/stores/toast";
import ConfirmDialog from "@/components/ConfirmDialog.vue";
const route = useRoute();
const router = useRouter();
const toast = useToastStore();
const snippet = ref<Snippet | null>(null);
const loading = ref(false);
const error = ref<string | null>(null);
const showDeleteConfirm = ref(false);
const id = computed(() => Number(route.params.id));
const canWrite = computed(() => {
const p = snippet.value?.permission;
return p === undefined || p === "owner" || p === "edit" || p === "admin";
});
const locations = computed(() => snippet.value?.snippet.locations ?? []);
// What this record absorbed. Merge keeps the target's fields and trashes the
// sources, so this line is the only visible trace that the variants existed.
const mergedFrom = computed(() => snippet.value?.snippet.merged_from ?? []);
function locParts(loc: { repo: string; path: string; symbol: string }): string[] {
return [loc.repo, loc.path, loc.symbol].filter((p) => p && p.trim());
}
// Un-merge (#2165)
const unmerging = ref<number | null>(null);
/** Only entries carrying what the source contributed can be reversed exactly.
* Without that, subtraction would be a guess that could strip call sites the
* survivor owns in its own right — so the control isn't offered. */
function canUnmerge(entry: { locations?: unknown[]; tags?: unknown[] }): boolean {
return canWrite.value && (!!entry.locations?.length || !!entry.tags?.length);
}
async function doUnmerge(sourceId: number) {
unmerging.value = sourceId;
try {
await unmergeSnippet(id.value, sourceId);
toast.show(`#${sourceId} pulled back out and restored`);
await load();
} catch (e: unknown) {
// 409 carries the reason the record's state makes it impossible — show it
// rather than a generic failure, since it's the actionable part.
const detail = (e as { body?: { error?: string } }).body?.error;
toast.show(detail || `Couldn't un-merge #${sourceId}`, "error");
} finally {
unmerging.value = null;
}
}
async function load() {
loading.value = true;
error.value = null;
try {
snippet.value = await getSnippet(id.value);
} catch (e: unknown) {
const status = (e as { status?: number }).status;
error.value = status === 404
? "This snippet couldn't be found."
: "Couldn't load this snippet.";
} finally {
loading.value = false;
}
}
onMounted(load);
async function copyCode() {
const code = snippet.value?.snippet.code ?? "";
try {
await navigator.clipboard.writeText(code);
toast.show("Code copied");
} catch {
toast.show("Couldn't copy — select and copy manually", "error");
}
}
async function confirmDelete() {
try {
await deleteSnippet(id.value);
toast.show("Snippet deleted");
router.push("/snippets");
} catch {
toast.show("Failed to delete snippet", "error");
} finally {
showDeleteConfirm.value = false;
}
}
</script>
<template>
<main class="snippet-detail">
<router-link to="/snippets" class="back-link"> Snippets</router-link>
<div v-if="loading" class="state-msg">Fetching the snippet</div>
<p v-else-if="error" class="error-msg">{{ error }}</p>
<template v-else-if="snippet">
<div class="detail-header">
<h1 class="snippet-name">{{ snippet.snippet.name }}</h1>
<div class="header-actions" v-if="canWrite">
<button class="btn-ghost" @click="router.push(`/snippets/${id}/edit`)">Edit</button>
<button class="btn-danger" @click="showDeleteConfirm = true">Delete</button>
</div>
</div>
<p v-if="snippet.shared" class="shared-notice">
Shared by <strong>{{ snippet.owner ?? "another user" }}</strong> their
suggestion, not one of your own records. Worth weighing on its merits
before you build on it.
</p>
<p v-if="snippet.snippet.when_to_use" class="when-to-use">
{{ snippet.snippet.when_to_use }}
</p>
<dl class="meta-grid">
<template v-if="snippet.snippet.signature">
<dt>Signature</dt>
<dd><code>{{ snippet.snippet.signature }}</code></dd>
</template>
<template v-if="locations.length">
<dt>{{ locations.length > 1 ? "Locations" : "Location" }}</dt>
<dd class="location-list">
<div v-for="(loc, i) in locations" :key="i" class="location">
<code v-for="(p, j) in locParts(loc)" :key="j">{{ p }}</code>
</div>
</dd>
</template>
<template v-if="snippet.snippet.language">
<dt>Language</dt>
<dd>{{ snippet.snippet.language }}</dd>
</template>
<template v-if="mergedFrom.length">
<dt>Merged from</dt>
<dd class="merged-from">
<span v-for="m in mergedFrom" :key="m.id" class="merged-entry">
<span>#{{ m.id }}</span>
<button
v-if="canUnmerge(m)"
class="unmerge-btn"
:disabled="unmerging === m.id"
:title="`Pull #${m.id} back out: restore it and remove the ${(m.locations ?? []).length} location(s) it contributed`"
@click="doUnmerge(m.id)"
>
{{ unmerging === m.id ? "…" : "un-merge" }}
</button>
<!-- Says why rather than hiding the control: a disabled thing with
no explanation reads as a bug. -->
<span
v-else-if="canWrite"
class="unmerge-na"
:title="`This merge predates per-source provenance, so what #${m.id} contributed isn't recorded. Restore it from the trash and adjust both records by hand — subtracting a guess could strip call sites this record genuinely owns.`"
>
(not reversible)
</span>
</span>
<span class="merged-hint">
folded in here the originals are in the trash
</span>
</dd>
</template>
</dl>
<div class="code-block">
<div class="code-bar">
<span class="code-lang">{{ snippet.snippet.language || "code" }}</span>
<button class="btn-ghost btn-copy" @click="copyCode">Copy</button>
</div>
<pre><code>{{ snippet.snippet.code }}</code></pre>
</div>
<div v-if="snippet.tags.length" class="tag-row">
<span v-for="t in snippet.tags" :key="t" class="tag-pill">{{ t }}</span>
</div>
</template>
<ConfirmDialog
v-if="showDeleteConfirm"
title="Delete snippet"
:message="`Delete “${snippet?.snippet.name}”? This can be restored from the trash.`"
confirmLabel="Delete"
danger
@confirm="confirmDelete"
@cancel="showDeleteConfirm = false"
/>
</main>
</template>
<style scoped>
.snippet-detail {
max-width: 820px;
margin: 2rem auto;
padding: 0 var(--fs-layout-page-pad);
overflow-x: clip;
}
.back-link {
display: inline-block;
margin-bottom: 1rem;
font-size: 0.85rem;
color: var(--fs-text-secondary);
text-decoration: none;
}
.back-link:hover {
color: var(--fs-accent);
}
.state-msg,
.error-msg {
margin-top: 1rem;
}
.detail-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 1rem;
}
.snippet-name {
margin: 0;
font-family: var(--fs-font-mono);
font-size: 1.4rem;
word-break: break-word;
}
.header-actions {
display: flex;
gap: 0.5rem;
flex-shrink: 0;
}
.when-to-use {
margin: 0.75rem 0 1.25rem;
font-size: 1rem;
color: var(--fs-text-secondary);
line-height: 1.55;
}
/* Shown only for a record another user owns. Deliberately above the code: the
provenance has to be read before the implementation is trusted. */
.shared-notice {
margin: 0.75rem 0 0;
padding: 0.6rem 0.85rem;
border-left: 3px solid var(--fs-text-tertiary);
border-radius: 6px;
background: var(--fs-surface-raised);
font-size: 0.85rem;
line-height: 1.5;
color: var(--fs-text-secondary);
}
.meta-grid {
display: grid;
grid-template-columns: max-content 1fr;
gap: 0.4rem 1rem;
margin: 0 0 1.5rem;
}
.meta-grid dt {
font-size: 0.7rem;
text-transform: uppercase;
letter-spacing: 0.06em;
color: var(--fs-text-tertiary);
padding-top: 0.15rem;
}
.meta-grid dd {
margin: 0;
font-size: 0.9rem;
color: var(--fs-text-primary);
min-width: 0;
}
.meta-grid code,
.tag-row + * code {
font-family: var(--fs-font-mono);
font-size: 0.82rem;
background: color-mix(in srgb, var(--fs-accent) 12%, transparent);
color: var(--fs-accent-fg);
padding: 0.08rem 0.35rem;
border-radius: var(--fs-radius-sm);
word-break: break-all;
}
.location-list {
display: flex;
flex-direction: column;
gap: 0.35rem;
}
.location {
display: flex;
flex-wrap: wrap;
gap: 0.35rem;
align-items: center;
}
.merged-from {
display: flex;
flex-wrap: wrap;
gap: 0.35rem;
align-items: baseline;
}
.merged-hint {
color: var(--fs-text-tertiary);
font-size: 0.8rem;
}
.merged-entry {
display: inline-flex;
align-items: baseline;
gap: 0.3rem;
}
.unmerge-btn {
font-size: 0.72rem;
padding: 0.05rem 0.35rem;
border: 1px solid var(--fs-border-color);
border-radius: 4px;
background: transparent;
color: var(--fs-text-tertiary);
cursor: pointer;
}
.unmerge-btn:hover:not(:disabled) {
color: var(--fs-text-primary);
border-color: var(--fs-text-tertiary);
}
.unmerge-btn:disabled {
opacity: 0.6;
cursor: default;
}
.unmerge-na {
font-size: 0.72rem;
color: var(--fs-text-tertiary);
/* Cursor cues that the explanation is in the tooltip. */
cursor: help;
}
.code-block {
border: 1px solid var(--fs-border-color);
border-radius: var(--fs-radius-lg);
overflow: hidden;
background: var(--fs-surface-page);
}
.code-bar {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0.4rem 0.5rem 0.4rem 0.85rem;
border-bottom: 1px solid var(--fs-border-color);
background: var(--fs-surface-raised);
}
.code-lang {
font-size: 0.72rem;
text-transform: uppercase;
letter-spacing: 0.06em;
color: var(--fs-text-tertiary);
}
.btn-copy {
padding: 0.2rem 0.65rem;
font-size: 0.78rem;
}
.code-block pre {
margin: 0;
padding: 1rem;
overflow-x: auto;
}
.code-block code {
font-family: var(--fs-font-mono);
font-size: 0.85rem;
line-height: 1.6;
color: var(--fs-text-primary);
white-space: pre;
}
.tag-row {
display: flex;
flex-wrap: wrap;
gap: 0.4rem;
margin-top: 1.25rem;
}
.tag-pill {
font-size: 0.72rem;
padding: 0.15rem 0.5rem;
border-radius: 999px;
background: var(--fs-surface-raised);
color: var(--fs-text-secondary);
border: 1px solid var(--fs-border-color);
}
@media (max-width: 600px) {
.detail-header {
flex-direction: column;
}
.meta-grid {
grid-template-columns: 1fr;
gap: 0.15rem 0;
}
.meta-grid dd {
margin-bottom: 0.5rem;
}
}
</style>