issue-detail.ts
typescript
sha256:3ff9c9863a9891bdcde71b4a43228f66d0493e38b7cc1d09fe9eb7de774046b2
feat: add repair-commit wire endpoint (API parity with repa…
Opus 4.8
minor
⚠ breaking
1 day ago
| 1 | /** |
| 2 | * issue-detail.ts — Issue detail page module. |
| 3 | * |
| 4 | * Responsibilities: |
| 5 | * 1. Comment entrance animations (IntersectionObserver stagger). |
| 6 | * 2. Re-animate comments after HTMX swap (new comment submitted). |
| 7 | * 3. Copy issue URL to clipboard (keyboard shortcut). |
| 8 | * 4. Syntax-highlight CLI / MCP / REST code snippets (highlight.js). |
| 9 | * 5. Inject per-snippet copy buttons. |
| 10 | */ |
| 11 | |
| 12 | import hljs from 'highlight.js/lib/core'; |
| 13 | import bash from 'highlight.js/lib/languages/bash'; |
| 14 | import javascript from 'highlight.js/lib/languages/javascript'; |
| 15 | |
| 16 | hljs.registerLanguage('bash', bash); |
| 17 | hljs.registerLanguage('javascript', javascript); |
| 18 | |
| 19 | |
| 20 | // ── Comment entrance animations ─────────────────────────────────────────────── |
| 21 | |
| 22 | function animateComments(root: Element | Document = document): void { |
| 23 | const comments = root.querySelectorAll<HTMLElement>(".id-comment, .id-reply"); |
| 24 | if (!comments.length) return; |
| 25 | |
| 26 | const io = new IntersectionObserver((entries) => { |
| 27 | entries.forEach((entry, i) => { |
| 28 | if (!entry.isIntersecting) return; |
| 29 | const el = entry.target as HTMLElement; |
| 30 | el.style.animationDelay = `${i * 30}ms`; |
| 31 | io.unobserve(el); |
| 32 | }); |
| 33 | }, { threshold: 0.05 }); |
| 34 | |
| 35 | comments.forEach(el => io.observe(el)); |
| 36 | } |
| 37 | |
| 38 | // ── HTMX: re-animate on comment swap ───────────────────────────────────────── |
| 39 | |
| 40 | function bindHtmxSwap(): void { |
| 41 | document.body.addEventListener("htmx:afterSwap", (e: Event) => { |
| 42 | const target = (e as CustomEvent).detail?.target as HTMLElement | undefined; |
| 43 | if (!target) return; |
| 44 | if (target.id === "issue-comments" || target.closest("#issue-comments")) { |
| 45 | animateComments(target); |
| 46 | } |
| 47 | }); |
| 48 | } |
| 49 | |
| 50 | // ── Copy issue URL (keyboard shortcut) ─────────────────────────────────────── |
| 51 | |
| 52 | function bindCopyUrl(): void { |
| 53 | document.addEventListener("keydown", async (e: KeyboardEvent) => { |
| 54 | if (e.key !== "y" || e.ctrlKey || e.metaKey || e.altKey) return; |
| 55 | const active = document.activeElement; |
| 56 | if (active && (active.tagName === "INPUT" || active.tagName === "TEXTAREA")) return; |
| 57 | try { |
| 58 | await navigator.clipboard.writeText(window.location.href); |
| 59 | } catch { /* clipboard unavailable */ } |
| 60 | }); |
| 61 | } |
| 62 | |
| 63 | // ── Syntax highlighting ─────────────────────────────────────────────────────── |
| 64 | |
| 65 | function highlightSnippets(): void { |
| 66 | document.querySelectorAll<HTMLElement>('pre.isd-cli-snippet code').forEach(el => { |
| 67 | hljs.highlightElement(el); |
| 68 | }); |
| 69 | } |
| 70 | |
| 71 | // ── Copy buttons ────────────────────────────────────────────────────────────── |
| 72 | |
| 73 | const COPY_ICON = `<svg class="icon icon-copy" width="10" height="10" aria-hidden="true" focusable="false"><use href="#icon-copy"></use></svg>`; |
| 74 | const CHECK_ICON = `<svg class="icon icon-check" width="10" height="10" aria-hidden="true" focusable="false"><use href="#icon-check"></use></svg>`; |
| 75 | |
| 76 | function injectCopyButtons(): void { |
| 77 | document.querySelectorAll<HTMLElement>('.isd-snippet-wrap').forEach(wrap => { |
| 78 | if (wrap.querySelector('.isd-cli-copy')) return; |
| 79 | const pre = wrap.querySelector<HTMLElement>('pre.isd-cli-snippet'); |
| 80 | if (!pre) return; |
| 81 | |
| 82 | const btn = document.createElement('button'); |
| 83 | btn.className = 'isd-cli-copy'; |
| 84 | btn.setAttribute('aria-label', 'Copy to clipboard'); |
| 85 | btn.innerHTML = `${COPY_ICON}<span>copy</span>`; |
| 86 | |
| 87 | btn.addEventListener('click', async () => { |
| 88 | const code = pre.querySelector('code'); |
| 89 | const text = (code?.textContent ?? pre.textContent ?? '').trim(); |
| 90 | try { |
| 91 | await navigator.clipboard.writeText(text); |
| 92 | btn.classList.add('copied'); |
| 93 | btn.innerHTML = `${CHECK_ICON}<span>copied</span>`; |
| 94 | setTimeout(() => { |
| 95 | btn.classList.remove('copied'); |
| 96 | btn.innerHTML = `${COPY_ICON}<span>copy</span>`; |
| 97 | }, 2000); |
| 98 | } catch { /* clipboard unavailable */ } |
| 99 | }); |
| 100 | |
| 101 | wrap.appendChild(btn); |
| 102 | }); |
| 103 | } |
| 104 | |
| 105 | // ── Entry point ─────────────────────────────────────────────────────────────── |
| 106 | |
| 107 | export function initIssueDetail(_data?: Record<string, unknown>): void { |
| 108 | animateComments(); |
| 109 | bindHtmxSwap(); |
| 110 | bindCopyUrl(); |
| 111 | highlightSnippets(); |
| 112 | injectCopyButtons(); |
| 113 | } |
File History
1 commit
sha256:3ff9c9863a9891bdcde71b4a43228f66d0493e38b7cc1d09fe9eb7de774046b2
feat: add repair-commit wire endpoint (API parity with repa…
Opus 4.8
minor
⚠
1 day ago