diff --git a/dev/scripts/dossier_page/template.html b/dev/scripts/dossier_page/template.html index 3770b66..7c0fd4d 100644 --- a/dev/scripts/dossier_page/template.html +++ b/dev/scripts/dossier_page/template.html @@ -349,6 +349,8 @@ button.dis { font-family: var(--font-body); font-size: 14px; padding: 3px 10px; .ev-src .src-t { font-size: 13px; color: var(--muted-foreground); } .ev-src blockquote { margin: 0; padding: 8px 12px; background: var(--card); border-left: 3px solid var(--primary); font-size: 14px; line-height: 1.55; } .ev-src blockquote.cmt { border-left-color: var(--s-prop); } +.ev-src .focus-open { justify-self: start; } +.ev-src .focus-pane { width: 100%; height: 72vh; border: 1px solid var(--border); background: var(--card); } .ev-dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 3px 10px; font-size: 14px; margin: 0; } .ev-dl dt { font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted-foreground); padding-top: 3px; } .ev-dl dd { margin: 0; min-width: 0; } diff --git a/infra/gitea/custom/public/assets/dossier/app.js b/infra/gitea/custom/public/assets/dossier/app.js index 5e1e8b2..0ee887f 100644 --- a/infra/gitea/custom/public/assets/dossier/app.js +++ b/infra/gitea/custom/public/assets/dossier/app.js @@ -235,6 +235,17 @@ document.addEventListener("click", (e) => { closeDrawer(); return; } + const focusBtn = e.target.closest("button[data-focus-src]"); + if (focusBtn && el.drawer.contains(focusBtn)) { + e.preventDefault(); + const src = focusBtn.getAttribute("data-focus-src") || ""; + if (!/^\/ui\/pdf\/[A-Za-z0-9]{6,12}\?protocol=[a-z0-9-]+$/.test(src)) return; + const frame = focusBtn.parentElement && focusBtn.parentElement.querySelector("iframe.focus-pane"); + if (!frame) return; + if (frame.getAttribute("src") !== src) frame.setAttribute("src", src); + frame.hidden = false; + return; + } if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return; const a = e.target.closest("a[href]"); if (a) { diff --git a/infra/gitea/custom/public/assets/dossier/cite.js b/infra/gitea/custom/public/assets/dossier/cite.js index 21e4ad0..e1f22ba 100644 --- a/infra/gitea/custom/public/assets/dossier/cite.js +++ b/infra/gitea/custom/public/assets/dossier/cite.js @@ -41,6 +41,26 @@ export const CITE_KIND = { const kindLabel = (k) => KIND_LABEL[k] || String(k || "fact").replace(/_/g, " "); const linkable = (cite) => cite.kind !== "cpt_book" && /^https?:\/\//i.test(cite.url || ""); +// A library key, same shape the llm viewer accepts. The pane path is a +// route on this host, never a citation URL (R10) and never cite.url. +const FOCUS_KEY = /^[A-Za-z0-9]{6,12}$/; + +/** Same-origin path of the focus pane for this source, or "" when the + * source has no library key or is a licensed book. */ +export function focusPath(cite) { + if (!cite || cite.kind === "cpt_book") return ""; + const key = String(cite.item_key || ""); + if (!FOCUS_KEY.test(key)) return ""; + const protocol = cite.kind === "fr_para" || cite.kind === "fr_page" ? "cms-disposition" : "comment-stance"; + return `/ui/pdf/${key}?protocol=${protocol}`; +} + +function focusControls(cite) { + const src = focusPath(cite); + if (!src) return ""; + return ``; +} + /** A cite as a link that opens apart, or as its locator when it has no url * (a licensed book says why its text is not shown). */ export function citeHtml(cite, { ref = "", refs = null } = {}) { @@ -131,7 +151,7 @@ export function groupHtml(facts, cite) { const items = facts .map((f) => `
  • ${esc(f.id)} · ${esc(kindLabel(f.kind))}${f.year ? " · CY" + esc(f.year) : ""} ${esc(f.text)}
  • `) .join(""); - return `
    ${facts.length} facts cite this source
    ${citeHtml(cite)}
    `; + return `
    ${facts.length} facts cite this source
    ${sourceHtml(cite)}
    `; } function valueText(v) { @@ -144,7 +164,7 @@ const filled = (v) => v !== null && v !== undefined && v !== "" && !(Array.isArr function sourceHtml(cite) { const what = [cite.locator && cite.locator !== cite.label ? cite.locator : "", CITE_KIND[cite.kind] || ""].filter(Boolean).join(" · "); - return `
    ${citeHtml(cite)}
    ${what ? `
    ${esc(what)}
    ` : ""}
    `; + return `
    ${citeHtml(cite)}
    ${what ? `
    ${esc(what)}
    ` : ""}${focusControls(cite)}
    `; } /** The evidence drawer for one fact. */ diff --git a/tests/lex/cite.test.mjs b/tests/lex/cite.test.mjs index b3c7853..e31c867 100644 --- a/tests/lex/cite.test.mjs +++ b/tests/lex/cite.test.mjs @@ -4,7 +4,7 @@ import { test } from "node:test"; import { equal as eq, ok } from "node:assert/strict"; import { readFileSync } from "node:fs"; -import { citeHtml, evidenceHtml, factHtml, groupHtml, tagged } from "../../infra/gitea/custom/public/assets/dossier/cite.js"; +import { citeHtml, evidenceHtml, factHtml, focusPath, groupHtml, tagged } from "../../infra/gitea/custom/public/assets/dossier/cite.js"; const fx = (name) => JSON.parse(readFileSync(new URL(`./fixtures/${name}.json`, import.meta.url), "utf8")); const H = fx("header"); @@ -202,6 +202,67 @@ test("an uncited tag in a run stays text and ends the run", () => { eq(count(h, "A ×2"), 1); }); +test("a library key opens the focus pane; the path is not a citation url", () => { + const cite = { + kind: "comment", + label: "Comment 9", + url: "https://example.test/c?x=1", + locator: "cmt", + item_key: "ABCD1234", + }; + eq(focusPath(cite), "/ui/pdf/ABCD1234?protocol=comment-stance"); + const h = evidenceHtml({ id: "F9", kind: "event", text: "t", cite }); + ok(h.includes('data-focus-src="/ui/pdf/ABCD1234?protocol=comment-stance"')); + ok(h.includes(">Open in focus pane")); + ok(h.includes('sandbox="allow-scripts allow-same-origin"')); + ok(h.includes('class="focus-pane"') && h.includes('title="Focus pane"')); + ok(h.includes('href="https://example.test/c?x=1"'), "the citation link stays the url the API gave"); + const pane = h.slice(h.indexOf("data-focus-src")); + ok(!pane.includes("https://") && !pane.includes("example.test")); +}); + +test("a federal register cite uses the disposition protocol", () => { + eq( + focusPath({ kind: "fr_para", label: "p", url: "https://example.test/fr", item_key: "RULEKEY1" }), + "/ui/pdf/RULEKEY1?protocol=cms-disposition", + ); + eq( + focusPath({ kind: "fr_page", label: "p", url: "", item_key: "RULEKEY1" }), + "/ui/pdf/RULEKEY1?protocol=cms-disposition", + ); +}); + +test("a licensed book never gets a focus pane, even with a library key", () => { + const cite = { + kind: "cpt_book", + label: "CPT 2019 p. 20", + url: "https://example.test/book", + locator: "CPT 2019 p. 20", + item_key: "BOOKKEY1", + }; + eq(focusPath(cite), ""); + const h = evidenceHtml({ id: "F2", kind: "formation", text: "t", cite }); + ok(!h.includes("focus-open") && !h.includes("/ui/pdf") && !h.includes("href")); +}); + +test("a missing, short, or odd key does not open the pane", () => { + const base = { kind: "study", label: "S", url: "https://example.test/s", item_key: "" }; + eq(focusPath(base), ""); + eq(focusPath({ ...base, item_key: "ABC" }), ""); + eq(focusPath({ ...base, item_key: "../etc/passwd" }), ""); + eq(focusPath({ ...base, item_key: "has space" }), ""); + eq(focusPath(null), ""); + eq(focusPath(undefined), ""); +}); + +test("groupHtml offers the pane for a keyed source and keeps the citation link", () => { + const cite = { kind: "study", label: "S", url: "https://example.test/s", locator: "", item_key: "STUDYKEY" }; + const h = groupHtml([mk("F1", "S")], cite); + ok(h.includes('data-focus-src="/ui/pdf/STUDYKEY?protocol=comment-stance"')); + ok(h.includes('href="https://example.test/s"')); + ok(!h.slice(h.indexOf("data-focus-src")).includes("example.test")); +}); + test("groupHtml lists the collapsed facts, each opening its own evidence", () => { const f1 = mk("F1", "A "); const h = groupHtml([f1, mk("F2", "A ")], f1.cite);