feat(f9): webview segmented mode toggle + authorship legend + author CSS
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+31
-6
@@ -10,16 +10,29 @@ import mermaid from "mermaid";
|
||||
// links it into the sealed shell via asWebviewUri).
|
||||
import "./preview.css";
|
||||
|
||||
declare function acquireVsCodeApi(): { postMessage(m: unknown): void };
|
||||
|
||||
interface RenderMessage {
|
||||
type: "render";
|
||||
mode: "changes" | "authorship";
|
||||
html: string;
|
||||
epoch: string;
|
||||
summary: { added: number; removed: number; changed: number };
|
||||
epoch?: string;
|
||||
summary?: { added: number; removed: number; changed: number };
|
||||
legend?: { claude: boolean; human: boolean };
|
||||
}
|
||||
|
||||
const vscodeApi = acquireVsCodeApi();
|
||||
const body = document.getElementById("cw-body")!;
|
||||
const header = document.getElementById("cw-epoch")!;
|
||||
const summary = document.getElementById("cw-summary")!;
|
||||
const legend = document.getElementById("cw-legend")!;
|
||||
const segs = Array.from(document.querySelectorAll<HTMLButtonElement>(".cw-seg"));
|
||||
|
||||
for (const seg of segs) {
|
||||
seg.addEventListener("click", () => {
|
||||
vscodeApi.postMessage({ type: "setMode", mode: seg.dataset.mode });
|
||||
});
|
||||
}
|
||||
|
||||
function themeFor(): "dark" | "default" {
|
||||
return document.body.classList.contains("vscode-dark") ||
|
||||
@@ -46,9 +59,21 @@ window.addEventListener("message", (event: MessageEvent<RenderMessage>) => {
|
||||
const msg = event.data;
|
||||
if (msg?.type !== "render") return;
|
||||
body.innerHTML = msg.html;
|
||||
header.textContent = `Track changes since ${msg.epoch}`;
|
||||
summary.innerHTML =
|
||||
`<span class="cw-add">+${msg.summary.added + msg.summary.changed}</span> ` +
|
||||
`<span class="cw-del">−${msg.summary.removed + msg.summary.changed}</span>`;
|
||||
for (const seg of segs) seg.classList.toggle("cw-seg-on", seg.dataset.mode === msg.mode);
|
||||
const authorship = msg.mode === "authorship";
|
||||
header.hidden = authorship;
|
||||
summary.hidden = authorship;
|
||||
legend.hidden = !authorship;
|
||||
if (authorship) {
|
||||
const parts: string[] = [];
|
||||
if (msg.legend?.claude) parts.push('<span class="cw-by-claude cw-swatch">Claude</span>');
|
||||
if (msg.legend?.human) parts.push('<span class="cw-by-human cw-swatch">You</span>');
|
||||
legend.innerHTML = parts.join(" ") || "no attribution yet";
|
||||
} else {
|
||||
header.textContent = `Track changes since ${msg.epoch ?? ""}`;
|
||||
summary.innerHTML =
|
||||
`<span class="cw-add">+${(msg.summary?.added ?? 0) + (msg.summary?.changed ?? 0)}</span> ` +
|
||||
`<span class="cw-del">−${(msg.summary?.removed ?? 0) + (msg.summary?.changed ?? 0)}</span>`;
|
||||
}
|
||||
void renderMermaid();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user